app-router icon indicating copy to clipboard operation
app-router copied to clipboard

Support if="{{condition}}" in app-route

Open dong77 opened this issue 10 years ago • 1 comments

When the app needs to handle routing based on user session, it's good to have conditional app-route support so we can write someting like this:

<app-route path="/account" if="{{loggedIn}}" element="account-page"></app-route>
<app-route path="/account" if="{{!loggedIn}}" redirect="login-page"></app-route>

Currently I have to rely on a on-state-change handler, but the UX is not ideal - the router first jumpted to one page then jump back to the page I directed.

dong77 avatar Feb 17 '15 02:02 dong77

I take it you were working off of this example? https://erikringsmuth.github.io/app-router/#/events#polymer-event-mapping

The URL should really be the only conditional when routing. Otherwise you break REST. You could maybe put conditional templates in a page but that doesn't seem idea. I think the best way is to route to a separate URL like /login if the user isn't logged in. You can do a redirect or replace the current URL with router.go() https://erikringsmuth.github.io/app-router/#/api#go.

erikringsmuth avatar Feb 17 '15 22:02 erikringsmuth