What's the different between react-router and Next.js

前端 未结 2 1988
借酒劲吻你
借酒劲吻你 2021-02-19 04:31

i\'m currently expolring ReactJS i saw NextJS and React Router

Can anyone tell me what\'s the pro cons between the two. I\'m not sure if it\'s right to compare the two,

2条回答
  •  渐次进展
    2021-02-19 04:47

    Jed's response sums it up pretty much, but here are some clarifications:

    • React router allows SSR, but does not implement it. You still need to make a server script that, at least, renders the app to a string and serve that to the client. You may need to do other things, like serve static files. NextJS does that for you.

    • SSR comes with a few caveats that NextJS also covers, mainly initial asynchronous functions (fetchs from APIs, for example). In a custom made system, you'll have to determine which functions you should call, usually based on the route, and pass the data to the components, usually with Redux

    I'm currently working on webs with both systems, and both have some pros and cons.NextJS has a specific way to declare routes and a very different way of moving through them, but making a custom system that deals with everything that NextJS covers is quite the work. I would not recommend making everything yourself unless it's really needed, and maybe check alternatives like Gatsby if asynchronous loads aren't a concern

提交回复
热议问题