Hi,
I am building a site which has two different part: a website and a game. All pages of the site have some common elements (a navbar and a footer) which must not appear on the game related pages. To achieve this, I decided to use two child routers: one for the game related pages and one for the site ones to easily include the navbar and the footer on all the pages. I want to have URLs like: /game/something
(ie with a /game
prefix for all routes) for the game and something like /synopsis
for the site (ie without a prefix for my routes).
My problem is that I get route not found errors for all routes of the site except the homepage (the empty route of the child router).
I tried to rely on config.mapUnknownRoutes
to redirect unknown routes to the site child router but all I can get is the homepage. Here is my config.mapUnknownRoutes
function:
config.mapUnknownRoutes(instruction => {
// moduleid maps to the subrouter. If I change it to point to a page, I get `plugin.load is undefined` errors.
return { route: 'site', moduleId: 'site/site' };
});
I also saw issues for something similar (https://github.com/aurelia/router/issues/117, https://github.com/aurelia/router/issues/27) but it looks that the only fixed case is for the homepage.
The configuration of my routers:
In app.js
:
configureRouter(config, router) {
this.router = router;
config.title = 'Arena of Titans';
config.options.pushState = true;
config.map([
{
route: '',
name: 'site',
moduleId: 'site/site',
nav: true,
title: 'Homepage',
}, {
route: 'game',
name: 'game',
moduleId: 'game/game',
nav: true,
title: 'Game',
},
]);
}
In my site sub-router:
configureRouter(config, router) {
// config.baseUrl = 'site';
config.baseUrl = '/';
config.options.pushState = true;
config.map([
{
route: [''],
name: 'home',
moduleId: './routes/home/home',
nav: false,
title: 'Home',
},
{
route: ['synopsis'],
name: 'synopsis',
moduleId: './routes/synopsis/synopsis',
nav: false,
title: 'Synopsis',
},
]);
}
Is it possible to do what I want or should I declare the routes of the site in the main router and use if.bind
to show/hide the navbar and the footer?