See this sandbox with a router demo: https://codesandbox.io/s/mo6llw3xy9.
Notice that Home and Settings both have the same layout but profile uses a child router to render a slightly different layout. I imagine something like this (psuedo-code, wrote from memory, might not compile):
app.html
<template>
<router-view></router-view>
</template>
app.js
export class App {
router: Router;
configureRouter(config: RouterConfiguration, router: Router): void {
this.router = router;
config.map([
{ route: '', moduleId: PLATFORM.moduleName('layouts/default') },
{ route: 'custom', moduleId: PLATFORM.moduleName('layouts/custom') },
]);
}
}
layouts/default.html
<template>
<nav></nav>
<h1>I am a layout with top nav</h1>
<router-view></router-view>
</template>
layouts/default.ts
export class DefaultLayout {
router: Router;
configureRouter(config: RouterConfiguration, router: Router): void {
this.router = router;
config.map([
{ route: '', moduleId: PLATFORM.moduleName('../pages/home') },
{ route: 'about', moduleId: PLATFORM.moduleName('../pages/about') },
]);
}
}
layouts/custom.html
<template>
<h1>I am a layout with bottom nav</h1>
<router-view></router-view>
<nav></nav>
</template>
layouts/default.ts
export class CustomLayout {
router: Router;
configureRouter(config: RouterConfiguration, router: Router): void {
this.router = router;
config.map([
{ route: 'user', moduleId: PLATFORM.moduleName('../pages/user/profile') },
{ route: 'admin', moduleId: PLATFORM.moduleName('../pages/admin/dashboard') },
]);
}
}
Usage:
The urls host.com/
and host.com/about
will load the home and about pages in the default layout while host.com/custom/user
and host.com/custom/admin
will load the user and admin pages with the custom layout.
Another thought I had was just to create the layouts as components and wrap each page’s view with it. Something like:
about.html
<template>
<default-template>
<h1>About</h1>
</default-template>
</template>
user.html
<template>
<custom-template>
<h1>User</h1>
</custom-template>
</template>
You could probably also achieve this with decorators.