Skip to content

Instantly share code, notes, and snippets.

@rdemetrescu
Last active October 27, 2017 14:31
Show Gist options
  • Select an option

  • Save rdemetrescu/2cbb0255f2077c30921810bff766de3c to your computer and use it in GitHub Desktop.

Select an option

Save rdemetrescu/2cbb0255f2077c30921810bff766de3c to your computer and use it in GitHub Desktop.
Issues with child routers and view router with layout
<template>
<require from="./nav-bar"></require>
<h1>Main router</h1>
<div>
<label>
<input type="checkbox" checked.bind="useLayout">
Use custom layout
</label>
</div>
<nav-bar router.bind="router"></nav-bar>
<router-view if.bind="!useLayout"></router-view>
<router-view layout-view="layout.html" if.bind="useLayout"></router-view>
</template>
export class App {
constructor() {
this.useLayout = false;
}
configureRouter(config, router) {
this.router = router;
config.title = 'Aurelia';
config.map([
{ route: ['child1', ''], name: 'child1', moduleId: './child1', nav: true, title: 'Child 1' },
{ route: 'child2', name: 'child2', moduleId: './child2', nav: true, title: 'Child 2' }
]);
}
}
<template>
<require from="./nav-bar"></require>
<div slot="myslot">
<h2>Child 1</h2>
<nav-bar router.bind="router"></nav-bar>
<router-view></router-view>
</div>
</template>
export class Child1 {
configureRouter(config, router) {
this.router = router;
config.map([
{ route: ['page1', ''], name: 'page1', moduleId: './page1', nav: true, title: 'page 1' },
{ route: 'page2', name: 'page2', moduleId: './page2', nav: true, title: 'page 2' }
]);
}
}
<template>
<require from="./nav-bar"></require>
<div slot="myslot">
<h2>Child 2</h2>
<nav-bar router.bind="router"></nav-bar>
<router-view></router-view>
</div>
</template>
export class Child2 {
configureRouter(config, router) {
this.router = router;
config.map([
{ route: ['page3', ''], name: 'page3', moduleId: './page3', nav: true, title: 'page 3' },
{ route: 'page4', name: 'page4', moduleId: './page4', nav: true, title: 'page 4' }
]);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
<template>
<div style="border: 5px dashed red; padding: 20px">
<p>inside layout.html</p>
<slot name="myslot"></slot>
</div>
</template>
<template>
<ul repeat.for="nav of router.navigation">
<li><a href.bind="nav.href" class="${nav.isActive ? 'active' : ''}">${nav.title}</a></li>
</ul>
</template>
import { bindable } from 'aurelia-framework';
export class NavBar {
@bindable() router;
}
<template>
<h3>Page 1</h3>
</template>
export class Page1 {
}
<template>
<h3>Page 2</h3>
</template>
export class Page2 {
}
<template>
<h3>Page 3</h3>
</template>
export class Page3 {
}
<template>
<h3>Page 4</h3>
</template>
export class Page4 {
}
.active { color: red; font-weight:bold; };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment