简体   繁体   English

可以用 Next.js 完全替代 React-Router 吗?

[英]Can use Next.js to replace React-Router totally?

Previously, I am using React + React-Router, I think the react-router is kind of complicated, I think Next.js's router is more straightforward, so my question is: can Next.js replace react-router totally?之前我用的是React + React-Router,我觉得react-router有点复杂,我觉得Next.js的router更直接,所以我的问题是:Next.js可以完全替代react-router吗? I am not familiar with Next.js, is there anyone can give me some suggestion?我对 Next.js 不熟悉,有人可以给我一些建议吗?

NextJS creates routes with the information from your local pages directory. NextJS 使用本地页面目录中的信息创建路由。 While this is much simpler than the other configurations, there are two disadvantages for this approach:虽然这比其他配置简单得多,但这种方法有两个缺点:

  1. It cannot create dynamic routes它不能创建动态路由
  2. It cannot create nested routes它不能创建嵌套路由

NextJS prefers a custom Node server to get past these disadvantages. NextJS 更喜欢自定义节点服务器来克服这些缺点。 If you would like a shortcut, Next Routes could help.如果您想要捷径, Next Routes可以提供帮助。

While you could certainly use React Router on the client side, it will not support SSR, so server side navigation is a big No. You would also have to move to HashRouter instead of BrowserRouter.虽然您当然可以在客户端使用 React Router,但它不支持 SSR,因此服务器端导航是一个很大的问题。您还必须转向 HashRouter 而不是 BrowserRouter。 You can find the issue here .您可以在此处找到问题。 It would certainly be better to use NextJS router for supporting functionalities like dynamic imports and prefetching.使用 NextJS 路由器来支持动态导入和预取等功能肯定会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM