Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a fallback route to catch unknown pages in backbone.js

Tags:

backbone.js

I have a set of routes set up like the following:

routes: {
  '!/home': 'home',
  '!/home/:page': 'home'
}

What I'm wondering is, how do I configure a route such that if the user requests an unknown page I can easily redirect to a static 404.html page?

like image 513
Darrell Brogdon Avatar asked Aug 25 '11 20:08

Darrell Brogdon


1 Answers

In your Router (the first two routes are for example):

routes: {
  "path/": "objectList",
  "path/:id": "objectItem",
  ":whatever": "notFound"
}

The last is the most general route possible, and will pick up everything not recognized by more specific routes.

like image 51
Elf Sternberg Avatar answered Nov 15 '22 10:11

Elf Sternberg