Router issue with multiple routes for the same page with different conditions
See original GitHub issueThis currenty throws a RuntimeException(Unspecified action for page Dashboard at Path(/))
if the user is logged in:
val loggedInRoutes = emptyRule |
staticRoute("/", Page.Dashboard) ~> render(Dashboard())
val routes = emptyRule |
staticRoute("/login", Page.Login) ~> render(Login()) |
(staticRoute("/", Page.Dashboard) ~> redirectToPage(Page.Login)(Redirect.Push))
.addCondition(_ => CallbackTo { !Authentication.isLoggedIn })(_ => None) |
loggedInRoutes.addCondition(_ => CallbackTo { Authentication.isLoggedIn })(_ =>
redirectToPage(Page.Login)(Redirect.Push))
routes.notFound(redirectToPage(Page.Dashboard)(Redirect.Replace)).renderWith(layout)
What I would like to achieve is the user to be redirected to the /login page if he tries to access a protected route without being logged in, and to be redirected to / if he tries to access a non-existent one. Since / is also a protected route currently, it should redirect to /login if the user is not authenticated.
Seems like the system gets confused by having to rules for the same Page with different conditions, which are mutually exclusive, so one of them should ALWAYS trigger. This shouldn’t be a routing error.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
React Router: how to have the same route in multiple ...
It seems as if when the user is logged in, it first renders the Route in the return statement when there is no...
Read more >Solved: Problems with 2 Static routes in the same router
The most common cause of this behavior is that the router has 2 routes for the destination and is using both of them...
Read more >Angular Router: Child Routes, Auxiliary Routes, Master Detail
This means that routing is not based anymore on using the # part of the URL, which is used to link directly to...
Read more >Ultimate React Router v6 Guide
If you want to render two different sections of content that both depend on the URL of the application then you need multiple...
Read more >Routing (Symfony Docs)
If you define multiple PHP classes in the same file, Symfony only loads the routes of the first class, ignoring all the other...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closed via #616
By failing early what do you mean? compile time, or runtime? The runtime exception that occurs, doesn’t really satisfy the early failing though, so I guess this is either a bug that needs fixed / feature that has to be added, or a better error message added.