TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

React Router v5

156 pointsby jsdev93about 6 years ago

24 comments

johnfnabout 6 years ago
Using react router on one of my personal projects (~ 30k loc) was probably one of my largest regrets. At every turn it seemed designed to do the thing I wouldn’t expect, or have arbitrary restrictions that made my life tougher.<p>Some examples:<p>* there&#x27;s no relative routes <a href="https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;2172" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;2172</a><p>* there&#x27;s no way to refresh the page <a href="https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;1982" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;1982</a> (&quot;that&#x27;s your responsibility, not ours&quot;)<p>* The scroll position will stick when you navigate to a new route, causing you to need to create a custom component wrapper to manage scrolling <a href="https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;3950" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;3950</a><p>* React router&#x27;s &lt;Link&gt; do not allow you to link outside of the current site <a href="https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;1147" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;react-router&#x2F;issues&#x2F;1147</a> so you have to make an &lt;a&gt; in those cases. This doesn’t sound bad, but it’s particularly frustrating when dealing with dynamic or user generated content. Why can’t they handle this simple case?<p>* Navigating to the same page would not actually reload the page, it would just trigger a componentDidMount() on all components in the page again, which led me to have a lot of bugs when I did some initialization in my constructor
评论 #19452173 未加载
评论 #19449597 未加载
评论 #19449545 未加载
评论 #19450770 未加载
评论 #19449603 未加载
评论 #19449563 未加载
评论 #19449581 未加载
评论 #19457785 未加载
评论 #19452744 未加载
mythzabout 6 years ago
I usually shudder when I see React Router major versions which usually result in hard breaks that takes hours to migrate existing code bases to, so I&#x27;m pleasantly surprised to see:<p>&gt; v5 is fully backwards compatible with 4.x<p>It appears the major version bump was due to package configuration changes instead of major API code changes.
评论 #19449353 未加载
评论 #19449442 未加载
评论 #19449548 未加载
anuragabout 6 years ago
We migrated from React Router to Reach Router (<a href="https:&#x2F;&#x2F;reach.tech&#x2F;router" rel="nofollow">https:&#x2F;&#x2F;reach.tech&#x2F;router</a>) and found it to be better in a few ways:<p>* Built-in focus management.<p>* Smaller library size.<p>* Implicit route matching that Just Works.<p>* More comprehensive docs with live examples.<p>Migration was easy. Highly recommended.
评论 #19450346 未加载
评论 #19449617 未加载
评论 #19450169 未加载
评论 #19451282 未加载
评论 #19449489 未加载
评论 #19449479 未加载
codesparkleabout 6 years ago
react-router depends on the ReactTraining&#x2F;history package for browser navigation support.<p>On 10 June 2017, an mind-bogglingly ill-conceived pull request[1] was merged, which causes <i>invalid</i> URLs to be pushed to the browser history, breaking the back button and page refresh in many scenarios.<p>Ever since, users have practically been begging the maintainer to fix the bug[2] and implementing hacky workarounds[3].<p>In a twist of irony, the contributor who originally introduced the bug has:<p>a) switched their own competing router package to a different history implementation[4]<p>b) argued that fixing the bug (which was introduced in a patch release) would require a major version bump, implying it would be better to let it remain broken[5].<p>I concede that the software is open source, and nobody is entitled to make any demands of the maintainers. Nevertheless, I pity the countless end-users who are left wondering why the most basic functionality of their web browsers is broken.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;history&#x2F;pull&#x2F;465" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;history&#x2F;pull&#x2F;465</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;history&#x2F;issues&#x2F;505" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;history&#x2F;issues&#x2F;505</a><p>[3]: <a href="https:&#x2F;&#x2F;github.com&#x2F;elastic&#x2F;kibana&#x2F;pull&#x2F;32365" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;elastic&#x2F;kibana&#x2F;pull&#x2F;32365</a><p>[4]: <a href="https:&#x2F;&#x2F;github.com&#x2F;pshrmn&#x2F;curi&#x2F;commit&#x2F;e850bcd9297398653a79b903f35818cb2df7738c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pshrmn&#x2F;curi&#x2F;commit&#x2F;e850bcd9297398653a79b9...</a><p>[5]: <a href="https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;history&#x2F;pull&#x2F;656" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ReactTraining&#x2F;history&#x2F;pull&#x2F;656</a>
评论 #19450669 未加载
artellectualabout 6 years ago
I migrated away from react-router because from v3 to v4 broke everything that made sense. Things became wildly more complicated.<p>I&#x27;m now extremely happy with my new router of choice router5 (not to be confused with React Router 5) <a href="https:&#x2F;&#x2F;router5.js.org" rel="nofollow">https:&#x2F;&#x2F;router5.js.org</a>.
评论 #19450405 未加载
评论 #19449900 未加载
评论 #19450268 未加载
评论 #19451186 未加载
评论 #19450042 未加载
评论 #19451706 未加载
评论 #19450946 未加载
评论 #19455771 未加载
joshwcomeauabout 6 years ago
Hi reader unfamiliar with React Router! Just a heads up - these comments are not representative of typical React Router users. I work with React Router every day, and my co-workers and I love it.<p>Something about HN gives people license to air all of their nitpick grievances, and make it seem like SUcH A bIg DEaL OmG WorST LiBRarY EVArR!11<p>To the authors, maintainers, and contributors: Thank you for making the ecosystem better. It makes our work easier.
评论 #19452875 未加载
davnicwilabout 6 years ago
Interesting to see the reason they had to do a major version bump, because of the usage of ^ in their internal dependencies meaning that you could get a mismatch between versions of the two internal sub packages react-router and react-router-dom.<p>The solution? Pinning the version to an exact number.<p>I <i>always</i> do this now as a policy, for everything, even when I&#x27;m using lockfiles though it shouldn&#x27;t strictly be necessary, because I&#x27;ve been burned by ^ too many times. There&#x27;s this ideal world expectation of ^ that it will magically give you upgrades for free without changes in behaviour, but breaking changes in behaviour occur <i>all the time</i> in minor and patch version updates in real world npm.<p>I think this is an intractable problem - mistakes will always be made, even when people try really hard, and over 100s of dependencies in a project you&#x27;re therefore quite likely to see these mistakes fairly regularly.
anonovaabout 6 years ago
I&#x27;ve never been a fan of React Router (mostly I don&#x27;t get why defining routes with components is a good thing) and have been pleasantly surprised with how well Curi (<a href="https:&#x2F;&#x2F;curi.js.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;curi.js.org&#x2F;</a>) works. It&#x27;s nice to see it&#x27;s not completely tied to a JS framework.
评论 #19449641 未加载
评论 #19449536 未加载
jeswinabout 6 years ago
I recently implemented home grown routing in one of my apps - and was surpised to see that it was about 30 lines of simple code. You don&#x27;t really need to tie yourself to a third party lib and risk future upgrades. Wrote about it here: <a href="https:&#x2F;&#x2F;medium.com&#x2F;p&#x2F;9e2c7b036b0" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;p&#x2F;9e2c7b036b0</a>
评论 #19449877 未加载
steve_taylorabout 6 years ago
I had nothing but trouble whenever I used React Router. For example, sometimes paths would be appended to the URL instead of replacing it, making it grow indefinitely, and it wasn&#x27;t obvious why.<p>There were two API rewrites in a short space of time and it was extremely frustrating, especially since it seemed almost compulsory to be experienced with React Router (along with Redux) to be taken seriously by recruiters.<p>For my own projects, I started using page.js years ago and haven&#x27;t looked back.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;visionmedia&#x2F;page.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;visionmedia&#x2F;page.js</a>
评论 #19453874 未加载
评论 #19451113 未加载
ryanflorenceabout 6 years ago
Author here.<p>One more time for those in the back:<p>v0.x &gt; v1 Breaking changes<p>v1 &gt; v2 &gt; v3 a couple obscure breaking changes, but practically none<p><i>18 months pass</i><p>v3 &gt; v4 New, composable design, basically a new project<p>v3 still maintained, 3.5 years no changes. v4 2 years, no changes.<p>v4 -&gt; v5 was supposed to be 4.4, but an internal dependency &#x27;^&#x27; got us, so best choice was version bump to prevent problems.
评论 #19456457 未加载
mychaelabout 6 years ago
I advise everyone to move away from React Router.<p>Maintainers who have such blatant disregard for users should not be rewarded or celebrated.
评论 #19450234 未加载
评论 #19450494 未加载
评论 #19450207 未加载
binarynateabout 6 years ago
I&#x27;m surprised to see so many negative comments about react-router here. I&#x27;ve used react-router v4 in a half dozen projects without significant issues, and I think the API is pretty flexible and easy to work with. I&#x27;m glad to see the React Training folks continue working on it.
mhdabout 6 years ago
This is going to be awesome for React&#x27;s apparent main industry: Training. A new set of videos and code camps...
评论 #19452220 未加载
neyaabout 6 years ago
As someone who works with both React and VueJS on a daily basis, I find Vue Router to be much MUCH easier to work with, well documented and is really straightforward. Most importantly - It&#x27;s an official package from VueJS core team and not a third party, so it&#x27;s pretty much worry-free.
评论 #19453286 未加载
urs2102about 6 years ago
Probably the least stressful major version bump I&#x27;ve seen. Props to the team for solving the 4.4.x problem and pushing this out. Took a few minutes to update and now everything is great!
dmitryminkovskyabout 6 years ago
May I take this opportunity to recommend found? It’s great: <a href="https:&#x2F;&#x2F;github.com&#x2F;4Catalyzer&#x2F;found" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;4Catalyzer&#x2F;found</a>.
notamaanabout 6 years ago
Here&#x27;s an alternative which is being actively maintained: <a href="https:&#x2F;&#x2F;github.com&#x2F;frontarm&#x2F;navi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;frontarm&#x2F;navi</a>
antiheroabout 6 years ago
My heart warmed when they said they were maintaining backwards compatibility.
princesseabout 6 years ago
So many negative comments in here. Just wanted to let the maintainers know we use the library in multiple projects without issue and that we appreciate deeply the work that goes into it!
kabesabout 6 years ago
Anybody using ui-router? I used to use that one in angular and saw they have a react version now. But I&#x27;m not yet familiar enough with react to judge it.
revskillabout 6 years ago
Using React Component for routing has a benefit: Universal Routing, with all benefits of React inside the route itself (lifecycle, state, data fetching,...).
ivanhoeabout 6 years ago
&gt; There are no breaking changes in this release.<p>Nice, glad to see the project becoming more stable. Upgrading from v3 to v4 made us a lot problems...
mattdeboardabout 6 years ago
Exemplary release notes.