AmpersandJS / ampersand-router

Clientside router with fallbacks for browsers that don't support pushState. Mostly lifted from Backbone.js.
MIT License
70 stars 16 forks source link

Trigger current route callback again #18

Closed dhritzkiv closed 9 years ago

dhritzkiv commented 10 years ago

Say I am on the page /contact. Is there anyway to force the router to trigger the path to load again if I run router.navigate('/contact')? Currently, the router doesn't fire the route callback if it's already on that route (which is useful 95% of the time)

wraithgar commented 10 years ago

have you tried router.navigate('/contact', {trigger: true})?

dhritzkiv commented 10 years ago

Yep, have tried that. The router seems to know that it's already on /contact and doesn't do anything as a result.

kamilogorek commented 10 years ago

Dirty, but working way of doing this app.router[app.router.routes['/contact']]()

wraithgar commented 10 years ago

Yep you're right, didn't see that line https://github.com/AmpersandJS/ampersand-router/blob/master/ampersand-history.js#L186

try router.history.loadURL(router.history.fragment)

This could definitely be a new function in the router imo.

wraithgar commented 10 years ago

Even if one of those suggestions works I'm gonna repurpose this issue as a feature request.

dhritzkiv commented 10 years ago

Ah, much better than my solution of appending a random query string to the end. But yes, a specific flag (or other, more obvious mechanism) would be welcome. Thanks!

wraithgar commented 10 years ago

@dhritzkiv did either of those work? I'd love to hear if the router.history.loadURL(router.history.fragment) worked cause that's an easy thing to throw into a function in the router.

dhritzkiv commented 10 years ago

@wraithgar Yes, it did! (though the function name on router.history is loadUrl, and not loadURL).

wraithgar commented 9 years ago

reload() now exists.