erikringsmuth / app-router

Router for Web Components
https://erikringsmuth.github.io/app-router/
MIT License
611 stars 83 forks source link

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

Open dong77 opened 9 years ago

dong77 commented 9 years ago

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.

erikringsmuth commented 9 years ago

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.