-
Notifications
You must be signed in to change notification settings - Fork 26
Programmatic navigation
Tim Wisniewski edited this page Oct 2, 2016
·
2 revisions
How do I change the route from within my application? There has been a lot of conversation around this and the 4.0
release of choo will provide a consistent approach. In the meantime, you can use these methods:
If you use hash routing you can change the route by simply using:
window.location.hash = 'foo'
This will automatically trigger choo's built-in setLocation
reducer.
The default routing in choo uses HTML5's browser history API. There's no way for JavaScript to observe when a new state has been pushed via .pushState()
, so it's a two-command process.
send('location:setLocation', { location: 'foo' })
window.history.pushState({}, null, 'foo')