我正在尝试使用react路由器6.4。我正在使用最新的布局,我甚至尝试了旧的布局,我仍然得到一个错误,说文档没有定义。
我如何在一个nextjs项目中正确地设置react路由器。我正在使用它来呈现页面上的各个组件。
如何定义文档?
我正在_app. js文件中使用createBrowserRouter
function MyApp({ Component, pageProps }) {
const router = createBrowserRouter({
basename: "/",
routeConfig: [
{
path: "/",
component: Splash,
},
{
path: "/myaccount",
component: MyAccount,
},
{
path: "/profile",
component: Profile,
},
],
字符串
});
return (
<Provider store={store}>
<RouterProvider router={router} />
<Layout>
<Component {...pageProps} />
</Layout>
</Provider>
);
型
}
导出默认MyApp;
这是布局文件的内容
return (
<>
<NavBar />
{children}
</>
);
型
1条答案
按热度按时间kwvwclae1#
仅当您使用页面路由器而不是应用路由器时,禁用文件系统路由器才可用。
退房-https://nextjs.org/docs/pages/building-your-application/configuring/custom-server#disabling-file-system-routing
你能做到的
字符串