Closed ChrisMcKenzie closed 10 years ago
I hadn't thought of dynamically added routes yet. Could you throw together a gist showing how you want to use it?
Say I have an app the that gets it's route definitions from a remote source, I would grab the definitions (using core-ajax or jQuery or plain ol' js XHR) and create app-routes
in the router after their definitions have been loaded.
if my incoming route is say /home
and my current location is the same it should just set that route active imediately.
My thoughts for accomplishing this are: I don't particularly care for the idea of something like a change watcher as it adds unnecessary complexity (and I love the simplicity of this router) but if it had one of the two ability below it would serve my needs perfectly.
app-router.html:50
)Ah, I see! I should really come up with a better way to do that previous state check. I added it because I listen for popstate
and hashchange
events and browsers are inconsistent whether they trigger one or both.
I think I could do a few things.
popstate
and hashchange
both being triggered at the same timeregisterRoute(route)
or registerRoutes(routes)
functionLet me see if I can figure out the first option. Otherwise I'll go for one of the later two.
I played around with it and went with a variation that automatically initializes and can be manually initialized by setting init="manual"
then calling router.init()
later. This will keep the API as simple as possible for people not even touching the Javascript.
https://github.com/erikringsmuth/app-router#init
I also changed changeActiveRoute
to go
. That was unrelated, I just think it'll be a shorter name to call when I get the previous state issue worked out.
Thanks for the PR!
adding routes dynamically works great unless you are currently at the route that is being added