d4f / backbone-highway

Routing Backbone with style \o/
MIT License
19 stars 5 forks source link

Ability to unregister a route #43

Closed bpatram closed 6 years ago

bpatram commented 6 years ago

Is it possible to unregister a route? It seems trivial to remove it from the Router but difficult to remove from the highway store since there are no public methods/variables to mutate its store data.

ghost commented 6 years ago

Hi @bpatram !

Good catch, it seems I didn't think of removing a route. I think we can add a remove() method to the highway object for easier access. Something like this:

highway.route({
  name: 'home',
  path: '/',
  action () { /* Display home */ }
})

highway.remove({ name: 'home' })

Leveraging the store.find() method we can target the route to remove using the current url.

// Define a profile route
highway.route({
  name: 'profile'
  path: '/user/:name',
  action () { /* Display profile */ }
})

// Let's say the current path is /user/rascarlito
highway.remove({ path: window.location.pathname })

Sounds good?

ghost commented 6 years ago

Check #44