https://github.com/strml/backbone.routenotfound
Simple plugin that fires an event to let the application know that no routes matched, so you can fire a custom 404 handler.
https://github.com/strml/backbone.routenotfound
Last synced: 12 months ago
JSON representation
Simple plugin that fires an event to let the application know that no routes matched, so you can fire a custom 404 handler.
- Host: GitHub
- URL: https://github.com/strml/backbone.routenotfound
- Owner: STRML
- Created: 2013-03-03T16:51:05.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-03-03T16:59:01.000Z (about 13 years ago)
- Last Synced: 2025-04-11T03:11:40.633Z (12 months ago)
- Language: JavaScript
- Size: 109 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
backbone.routeNotFound
======================
Simple plugin that fires an event to let the application know that no routes matched, so you can fire a custom 404 handler.
Install
-------
Include backbone.routeNotFound after backbone.js and underscore.js.
If you're using any plugins that override Backbone.history.prototype.loadUrl, include this plugin *after* those plugins
to ensure changes to loadUrl are not overwritten.
Usage
-----
A example bit of code to redirect on an invalid route:
```javascript
// router.js
// ...
initialize: function(){
this.listenTo(Backbone.history, 'routeNotFound', this.onRouteNotFound);
},
onRouteNotFound: function(){
console.log("Route not found, redirecting...");
Backbone.history.navigate('', {trigger: true});
}
// ...
```