We found a way to do this our app -- both with and without doing that "nullrouter" thing I'd posted about before.
Without any modifications to routing, you can use can.route.attr('route') to get the string identifying the route pattern which was matched (e.g., ":section/"). Using the pushstate plugin, you only need to check this when routing initializes, since if a user manipulates the url by hand it'll cause a full page refresh. (That doesn't apply when using hashchange, though.)
- can.route.ready();
- if (!can.route.attr('route')) {
- // 404! This indicates that the normal routing stuff did not fire.
- }
- // else: the normal routing stuff was able to pick up the route and its params,
- // so we do not (and must not) handle the 'else' case here.
With our current 'nullrouter' setup, the app always calls our showPage() function, so we have a single entry point where we do the same sort of thing: if we have a valid route config then we show it, else we display a 404.