saschagrunert / yew-router

Router extension to yew
MIT License
28 stars 6 forks source link

Switch to correct route upon pageload, based on initial URL #214

Closed Boscop closed 4 years ago

Boscop commented 4 years ago

Currently, when the app is loaded, the Default route is active, even if the URL says otherwise. E.g. you can see it in my example here: https://github.com/saschagrunert/yew-router/pull/213. If the user came to the page by entering a certain url, we should route to it upon pageload. Not sure what the best event to listen to is, for this. E.g. there is DOMContentLoaded which fires before load (not waiting for assets to load). Not sure if DOMContentLoaded will fire before our wasm app is started, and if we register a handler for it in the wasm app, if we still catch the event that was fired before.. Related: https://stackoverflow.com/questions/2414750/difference-between-domcontentloaded-and-load-events https://stackoverflow.com/questions/7745124/event-which-triggers-before-domcontentloaded

issue-label-bot[bot] commented 4 years ago

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

saschagrunert commented 4 years ago

Yeah I agree. I can’t verify it right now but we may find a manual way for the user to trigger the routing based on the initial route. I think both are valid use cases:

Boscop commented 4 years ago

Yes, it's good to let users control this. E.g. If upon pageload, url and Default route differ, the app might want to set the url to match the Default route, instead of the other way round. The app would do it in the create method: I realized, it's possible already, without any changes to yew-router, I updated my history_state example to do this: It now does router_agent.send(yew_router::Request::GetCurrentRoute); in RootComponent::create(). But if upon pageload the url is invalid, and ends up mapping to the Default route, currently it doesn't set the url to match that route.

saschagrunert commented 4 years ago

Yeah cool. I also was not sure if the feature belongs to yew-router, but we could provide some helper methods or a setting to specify the behavior from the user side... :)