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.

Route conditions not evaluated in RouterCtl#set

See original GitHub issue

I added condition to my route (staticRoute("/profile", ProfilePage) ~> renderR(ctl => Profile(ctl))) .addCondition(grantPrivateAccess)(_ => redirectToPage(Home)(Redirect.Push))

When i use <a href="/profile"> or window.location.href = "/profile" it works, but when I use methods of RouterCtl (set(ProfilePage)) condition grantPrivateAccess isn`t checked and it goes to ProfilePage How can I fix it ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
japgollycommented, Feb 12, 2017

You’ve got impure code outside of Callback; side-effects must be captured inside Callback. To be specific, localStorage (just like a global variable) isn’t referentially-transparent and is the problem here.

Try changing

def grantPrivateAccess = {
    val rule: js.Any = global.window.localStorage.getItem("token")
    if(rule != null)
      CallbackTo(true)
    else
      CallbackTo(false)
  }

to this:

val grantPrivateAccess = CallbackTo {
    val rule: js.Any = global.window.localStorage.getItem("token")
    rule != null
  }
1reaction
japgollycommented, Feb 10, 2017

As a temporary hack, you could use RouterCtl#contramap to workaround this. So something like:

def temporaryWorkaround(r: RouterCtl[MyPage]): RouterCtl[MyPage] =
  r.contramap {
    case ProfilePage if !grantPrivateAccess() => Home
    case p => p
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Two static routes to same destination in routing table possible?
But both needs to be in routing table. Floating routes does not work because route with higher admin distance does not inserted into...
Read more >
Troubleshooting BGP Neighbor Adjacency
BGP Neighbor Adjacency issues occur every now and then, this lesson explains the most common issues and how to fix them.
Read more >
How Routing Information Protocol (RIP) works - TechTarget
If a router receives an update on a route, and the new path is shorter, it will update its table entry with the...
Read more >
Example: Forwarding Packets to the Discard Interface
The requests are sent to a router that does not forward the packets. The problematic routes are sometimes referred to as discard routes...
Read more >
SAP Cloud Integration - Define Router - SAP Help Portal
We recommend that you ensure that the routing branches of a router are configured with the same type of condition, either XML or...
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