【发布时间】:2021-08-29 16:14:36
【问题描述】:
我有一个Layout 组件,我在其中比较路由查询并根据它返回布局。
我要对比动态路由,比如invoices/invoice-1
我目前有以下组件,但正如您所见,configArrays.includes(pathname) 不起作用。
const config = {
layout1: ['/invoices/[id]'],
layout2: ['/route/sign-in'],
};
const Layout = ({ children }) => {
const { asPath } = useRouter();
const url = new Url(asPath, true);
const pathname = url.pathname;
if (config.layout1.includes(pathname)) {
return <Layout1>{children}</Layout1>;
}
if (config.layout2.includes(pathname)) {
return <Layout1>{children}</Layout1>;
}
return <DefaultLayout>{children}</DefaultLayout>;
};
【问题讨论】:
标签: javascript routes next.js