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

Viewed 2876

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? I am not familiar with Next.js, is there anyone can give me some suggestion?

1 Answers

NextJS creates routes with the information from your local pages directory. 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. If you would like a shortcut, Next Routes could help.

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. You can find the issue here. It would certainly be better to use NextJS router for supporting functionalities like dynamic imports and prefetching.

Related