question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router issue with multiple routes for the same page with different conditions

See original GitHub issue

This 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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
japgollycommented, Jan 6, 2020

Closed via #616

1reaction
axos88commented, May 17, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found