如何解决使用react router和nextjs时文档未定义的错误

pgpifvop  于 2023-08-04  发布在  React
关注(0)|答案(1)|浏览(116)

我正在尝试使用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}
</>
);

kwvwclae

kwvwclae1#

仅当您使用页面路由器而不是应用路由器时,禁用文件系统路由器才可用。
退房-https://nextjs.org/docs/pages/building-your-application/configuring/custom-server#disabling-file-system-routing
你能做到的

// next.config.js
module.exports = {
  useFileSystemPublicRoutes: false,
}

字符串

相关问题