Skip to content

Instantly share code, notes, and snippets.

@destroytoday
Created April 5, 2012 13:01
Show Gist options
  • Save destroytoday/2310892 to your computer and use it in GitHub Desktop.
Save destroytoday/2310892 to your computer and use it in GitHub Desktop.
Backbone.js facepalm
class AppRouter extends Backbone.Router
routes:
'users/:user': user
user: (user) ->
console.log 'navigated to user:', user
router = new AppRouter
Backbone.history.start { pushState: true }
# This changes the URL, but does NOT trigger the AppRouter.user function:
router.navigate 'users/destroytoday'
# This changes the URL and triggers the function:
router.navigate 'users/destroytoday', true
# This also works:
router.navigate 'users/destroytoday', { trigger: true }
# In my opinion, trigger should be true by default. Why would you want to change the URL without doing anything?
@tanaki
Copy link

tanaki commented Apr 5, 2012

"Why would you want to change the URL without doing anything?"
You could have tabs or a carousel with all the data loaded in the page and use different urls to have different states.
Then you have a unique url for each tabs or carousel item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment