【问题标题】:How do I render a component, not a page in NextJS?如何在 NextJS 中呈现组件而不是页面?
【发布时间】:2021-06-18 01:52:15
【问题描述】:

我正在尝试修复 NextJS 应用程序中位于身份验证内的按钮。该应用程序不将页面用于经过身份验证的路由,所有内容都是/#,我试图弄清楚如何从按钮路由设置组件。原始开发者不希望在身份验证中有任何页面路径。

是否有类似 React 中的流程,这样我可以路由到组件而不是页面?

<Router>
  <Switch>
    <Route path='/settings'>
      <Settings />
    </Route>
  </Switch>
<Router>

我觉得 withRouter 可能是关键,但我找不到组件所需的路径。

【问题讨论】:

    标签: react-router components next.js react-router-dom


    【解决方案1】:

    我认为你 approch 不是 nextjs 应用程序的最佳选择。 无论如何,您可以在 nextjs 配置中 disable the nextjs file system 路由并使用自定义服务器

    module.exports = {
      useFileSystemPublicRoutes: false,
    }
    

    然后就可以使用 react-router 组件了。 看看这个tutorial 看看更详细的例子。

    【讨论】:

      猜你喜欢
      • 2021-11-07
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-20
      • 2021-11-06
      • 2017-05-30
      相关资源
      最近更新 更多