我希望对特定 URL ( /dashboard)下的内容使用仅客户端路由。其中一些内容将来自 Contentful 并使用页面模板。这条路线的一个例子是{MYDOMAIN}/dashboard/{SLUG_FROM_CONTENTFUL}。这样做的目的是确保我在代理机构工作过的项目无法被抓取/访问,并且只有“雇主”登录后才能看到。
我的页面是通过gatsby-node.js. 添加身份验证/仅客户端路由的方式取自此示例。现在它的基础已经设置好并且工作正常,据我所知。但私人路线似乎只在以下情况下有效:
如果我已登录并导航到 /dashboard
Profile.js如果我没有登录并转到 /dashboard
Login.js所以这一切似乎都很好。问题出现在我去/dashboard/url-from-contentful但我没有登录时。我得到的是页面而不是被发送到/dashboard/login.
exports.createPages = async ({graphql, actions}) => {
const { createPage } = actions;
const { data } = await graphql(`
query {
agency: allContentfulAgency {
edges {
node {
slug
}
}
}
}
`);
data.agency.edges.forEach(({ node }) => {
createPage({
path: `dashboard/${node.slug}`,
component: path.resolve("src/templates/agency-template.js"),
context: {
slug: node.slug,
}, …Run Code Online (Sandbox Code Playgroud) 我在WP循环中有以下代码
<?php
// Get the selected taxonomies for the post type
$terms = get_the_terms( get_the_ID(), 'course_type' );
$classes = array();
if ( $terms && ! is_wp_error( $terms ) ){
foreach ( $terms as $term) {
$classes[] = $term->slug;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我要做的是只打印要在类中使用的WP_Term对象slug.
<div class="courses-search-result standout-box-shadow <?php print_r( $classes ); ?>">
Run Code Online (Sandbox Code Playgroud)
现在,我已经让它工作到一个点并在类中打印一个值 - 但它也打印了数组结构:
class="courses-search-result standout-box-shadow cilex-clearfix Array
(
[0] => apprenticeship
)
"
Run Code Online (Sandbox Code Playgroud)
我接近用PHP获取正确的代码吗?我对这门语言的了解是基本的,所以任何帮助都会非常感激.