Thursday, December 03, 2015

Aurelia - Unknown routes

So, today, I was working on getting the handler for my main entry point on my site. Basically, the idea is that there is one initial route that succeeds, everything else is a 404. But if you come in on the magic route, a call to the backend will verify that it is a valid request, and all of the routes will then appear.

But how to set up a catch-all route? A google search found nothing except links into the Aurelia source code. A request on the gitter channel was not answered. So I dug through the source and found the answer myself (I admit, asking on gitter was cheating - I should have just searched the source in the first place).

You can add a catch-all by calling mapUnknownRoutes on the original config object. So my configureRouter has the one route, and the call to mapUnknowRoutes to set the view model that handles unknown routes. In my case, it looks kinda like this:

configureRouter(config, router) {
  config.title = 'Wow! What a site';[
    { route: [ 'entry/:id'], moduleId: 'public/entry' }
My 404 view model is empty, and 404.html has the page I want everyone to see.


No comments: