Live data from Hacker News

React Router v5

reacttraining.com

31–40 of 90 posts

Re: React Router v5

#31

I migrated away from react-router because from v3 to v4 broke everything that made sense. Things became wildly more complicated. I'm now extremely happy with my new router of choice router5 (not to be confused with React Router 5) https://router5.js.org .

Thank you, this looks excellent! Finally a router that doesn't force you to define your UI by splitting everything up into their top-level view components. I want the router to give me the state, and then get the hell out of the way so I can fully manage the UI myself.

I've had a look at react-router multiple times over the years, and the best thing going for them seems to have been that they managed to squat that generic name early on. From the docs and GitHub, it's always been abundantly clear that the "current version sucks, mistakes were made, next version will totally fix everything" again and again.

Re: React Router v5

#32
post #28
post #26

Earlier quoted context omitted.

> The solution to the external links issue is a one-liner. It is most definitely not a one-liner. > Making the page scroll to the top when navigating to a new page is trivial. So do it for me. There’s no reason a routing library should break default behavior. > That's exactly what it's supposed to do. It's a client side routing solution. (I'm also pretty sure that it doesn't remount) Then it’s “supposed” to have inco…

> It is most definitely not a one-liner. const LinkWrapper = ({to, ...rest}) => to.startsWith(window.location.origin) ? : ; > So do it for me. There’s no reason a routing library should break default behavior. It's not default behavior for a client side router. Making it automatically scroll to the top would save you a few lines of code while creating a monumental headache for those who need it to retain the scroll p…

I guess you might need a polyfill for window.location.origin depending on target browsers, and since they discussed relative urls earlier I guess they want to handle relative urls as well and probably want to also handle starts with //.

I think generally what happens, based on what I often end up doing and what I've seen in bigger projects that depend on React Router, is you make a linker component to handle issues, and in fairness you end up not having a 1 liner then.

Re: React Router v5

#33
post #12

I've never been a fan of React Router (mostly I don't get why defining routes with components is a good thing) and have been pleasantly surprised with how well Curi ( https://curi.js.org/ ) works. It's nice to see it's not completely tied to a JS framework.

> I don't get why defining routes with components is a good thing It makes the routes reactive. This is not necessary for smaller projects, but where it is needed this can be really helpful. The responsive route example shows this off well https://reacttraining.com/react-router/core/guides/philosoph...

I find the opposite true. Components based routing is fine for small applications, but in a sizable application you will inevitable end up with several things that doesn't fit nicely into the simplistic router component model, and now you're shit out of luck and have to try to jimmy-rig in some escape hatch.

It's a much more flexible model to have the router update your state in Redux or whatever, and then you take care of all the rendering and component hierarchies yourself.

Re: React Router v5

#34
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.

The solution? Pinning the version to an exact number.

I always do this now as a policy, for everything, even when I'm using lockfiles though it shouldn't strictly be necessary, because I've been burned by ^ too many times. There'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 all the time in minor and patch version updates in real world npm.

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're therefore quite likely to see these mistakes fairly regularly.

Re: React Router v5

#35
This is going to be awesome for React's apparent main industry: Training. A new set of videos and code camps...

Re: React Router v5

#36

I migrated away from react-router because from v3 to v4 broke everything that made sense. Things became wildly more complicated. I'm now extremely happy with my new router of choice router5 (not to be confused with React Router 5) https://router5.js.org .

Router5 is awesome (but needs some getting used to). I remember being so fed up with React Router that I spent sometime implementing some functionality that existed in React Router before 1.x, and that still is missing (like route names).

And used router5 for that.

Didn't even need that many hacks: https://gist.github.com/dmitriid/675ceff4bd07ec6cdf06a560d72...

Re: React Router v5

#37

Earlier quoted context omitted.

Yeah that was my first reaction when I saw the title, "How hard is it going to be this time?" since it took me 2 days to migrate to the v4 last time.

Why upgrade?

Because if you don't upgrade, you are stuck with whatever version of React created at the time. You don't get stability & performance improvements, bug fixes, you can't potentially install some newer libraries requiring the new version. Not keeping up with upgrades is making the code rot slowly.

Re: React Router v5

#38
post #28
post #26

Earlier quoted context omitted.

> The solution to the external links issue is a one-liner. It is most definitely not a one-liner. > Making the page scroll to the top when navigating to a new page is trivial. So do it for me. There’s no reason a routing library should break default behavior. > That's exactly what it's supposed to do. It's a client side routing solution. (I'm also pretty sure that it doesn't remount) Then it’s “supposed” to have inco…

> It is most definitely not a one-liner. const LinkWrapper = ({to, ...rest}) => to.startsWith(window.location.origin) ? : ; > So do it for me. There’s no reason a routing library should break default behavior. It's not default behavior for a client side router. Making it automatically scroll to the top would save you a few lines of code while creating a monumental headache for those who need it to retain the scroll p…

This has a number of bugs. Links don’t have to start with window.location.origin, they can just start with /. You didn’t pass in ...rest into the a tag, but oh did you know that the props of a are not the same type as the props to Link? They’re not - so even if you did that it wouldn’t have worked. Oh, and don’t forget to handle “javascript:” prefixed links - those are valid too. Oh and good luck getting this to type check with Typescript. You might be able to pull off something fancy with subtraction types, but who knows if it’ll continue to work when react router upgrades next year.

You might think I’m being overly pedantic. Perhaps I am - however in the course of my site I ran into each and every one of these issues after starting out with a clever one liner much like the one you provided. And every time I fixed one I wondered why react router couldn’t handle this for me.

> Making it automatically scroll to the top would save you a few lines of code while creating a monumental headache for those who need it to retain the scroll position.

Maybe I’m just not being charitable enough, but it beats me how a boolean flag is a “monumental headache” but all the above work with absolute links is an obvious thing anyone can do.

Re: React Router v5

#39
I advise everyone to move away from React Router.

Maintainers who have such blatant disregard for users should not be rewarded or celebrated.

Re: React Router v5

#40
post #5

We migrated from React Router to Reach Router ( https://reach.tech/router ) and found it to be better in a few ways: * Built-in focus management. * Smaller library size. * Implicit route matching that Just Works. * More comprehensive docs with live examples. Migration was easy. Highly recommended.

I get the sense that Reach Router is no longer maintained despite what the project owner says, plus there's the fact that he's been rehired into the React Router team.
Post reply on HN