-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about "unreachable" routes #1923
Comments
+1 puzzled over this problem for a bit the other night before realizing I needed to switch the route order. |
👍 this would be really helpful |
👍 |
👍 after a tweet from @knowbody I've made a rough start on this. Hopefully get something into PR state soon :) |
@jackfranklin feel free to send a [WIP] PR so other ppl can help you as well. thanks for taking it :) |
As mentioned in #2351, we probably want to implement this as an opt-in, development/testing-only behavior. Ideally, this can be a |
I'm switching this issue to a discussion because there are two ways forward here that are going to have implications for how matching works. Option 1This is my preferred approach. We use a Pareto-principle-style approach where we check route reachability by constructing paths corresponding to leaf routes, then run the matching algorithm to make sure that those paths resolve to the expected routes. This approach has two main benefits:
The main drawback compared to option 1:
Option 2This is @mjackson's preferred approach. We use a Hapi-style static check that statically analyzes routes and paths to make an absolute determination of reachability v route conflicts. The main advantages:
The main drawbacks:
Also, @KyleAMathews, you're already on this thread, and I recall hearing that you were a Hapi user. Any thoughts here? |
I did/do use Hapi (much reduced now that I use GraphQL). I've been perfectly happy with Hapi's routes but not sure how useful that feedback is as my routes are all very vanilla. It seems like the main advantage of express-style routes is their greater power/flexibility. Is there any common use cases or sites that have run into problems with our Hapi-style routes? |
A few notes – #2987 is an implementation of my option 1 above. The code in Hapi implementing their equivalent of option 2 is at https://github.com/hapijs/call. Consider the motivating example from #3098 (comment). Ignoring the optional path segment, if you want to do something like: <Route path="{category}" />
<Route path="{slug}" /> Then this won't work if we check for static reachability, since the <Route path=":category(foo|bar|baz)" />
<Route path=":slug" /> Or more broadly without static route conflict checking, you can do something like <Route path=":category" condition={isValidCategory} />
<Route path=":slug" /> |
The other issue here is that |
v4 has no routes, woo hoo! |
We should warn people who have routes that can never actually be reached because they are put after some other route that will always match first. For example, in this route config:
the
<Redirect>
will never actually be reached because the<Route>
that precedes it will always match thecomments
path.The text was updated successfully, but these errors were encountered: