Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Accommodate state in Router model #103

Closed
gehnaphore opened this issue Apr 19, 2015 · 6 comments
Closed

Accommodate state in Router model #103

gehnaphore opened this issue Apr 19, 2015 · 6 comments
Labels
Milestone

Comments

@gehnaphore
Copy link

First of all, thanks for such an interesting library. I'm having a lot of fun with it.

I'm trying to use the router component, but having some trouble. I'm building a single-page app, and I'm looking for some way to properly route the user based on global state. For example, if the user is not logged in, I'd like to direct them to a login page. Since in a single-page app this is all managed with client-side state, I'm looking for some way to redirect based on app state. But redirection doesn't seem to allow any state-based decisions.

I feel like I'm missing something. How would I, say, redirect a non-logged-in user (based on reference to JS local storage or some other local state) to a login page? I can substitute components, but I don't see how I could actually perform a redirect.

@japgolly
Copy link
Owner

There was some discussion in the gitter chat room a while back about this. It'll probably be best to ask there because I don't use stateful routes myself. But the answer I remember giving there was to use dynamic routes. There's detail and some examples in ROUTER.md and RouterTest.scala.

@ngbinh
Copy link

ngbinh commented Apr 22, 2015

@gehnaphore this may help: #100

@japgolly
Copy link
Owner

First of all, thanks for such an interesting library. I'm having a lot of fun with it.

Btw thank you and I'm happy to hear it :)

@japgolly
Copy link
Owner

Ok my brain learned to see this situation in a way that convinces me to entwine the Router and arbitrary state. (#107)

This is issue is accepted. In the next release (a few weeks away) the Router will change to accommodate this.

@japgolly japgolly changed the title Routing dependent on application state Accommodate state in Router model Apr 23, 2015
@japgolly japgolly removed the question label Apr 23, 2015
@japgolly japgolly modified the milestone: 0.9.0 Apr 23, 2015
@gehnaphore
Copy link
Author

Great to hear it, and excited to see what you come up with.

I started trying to figure out a better way of routing, and ended up researching Macro Paradise... and then deciding this problem didn't need to be solved immediately. :-)

japgolly added a commit that referenced this issue May 17, 2015
New router that:
* uses an ADT to represent pages
* allows rules to be composed and then modified collectively
* clarifies the difference between Router component and controller
* accomodates stateful logic

Addresses #96, #103, #102, #94
japgolly added a commit that referenced this issue May 17, 2015
New router that:
* uses an ADT to represent pages
* allows rules to be composed and then modified collectively
* clarifies the difference between Router component and controller
* accomodates stateful logic

Addresses #96, #103, #102, #94
@japgolly
Copy link
Owner

Closed via 93bbc5f.

There's a new Router coming in 0.9 that fixes this.

Routing rules can now be as stateful as you like, here's a small example.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants