Skip to content

Instantly share code, notes, and snippets.

@deap82
Last active June 16, 2018 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deap82/57677ba21248598d5b784dfb5940643c to your computer and use it in GitHub Desktop.
Save deap82/57677ba21248598d5b784dfb5940643c to your computer and use it in GitHub Desktop.
Aurelia Gist - child router issue
<template>
<ul id="menu">
<li><a href="#/Welcome">Welcome</a></li>
<li><a href="#/Products">Products</a></li>
<li><a href="#/Contact">Contact</a></li>
</ul>
<div id="content">
<router-view></router-view>
</div>
<div id="output-wrapper">
<div id="output"></div>
<button type="button" onclick="document.getElementById('output').innerHTML='';">Clear</button>
</div>
</template>
import { OutputService as output } from 'output-service';
export class App {
configureRouter(config, router) {
console.log('configureRouter');
config.map([
{ route: '', redirect: 'Welcome' },
{ route: 'Welcome', name: 'Welcome', moduleId: 'page-welcome' },
{ route: 'Products/:any?/:id?', name: 'Products', moduleId: 'page-products' },
{ route: ':any/:id?', name: 'Contact', moduleId: 'page-contact' }
]);
}
}
<!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>
export class OutputService {
static log(message) {
var outputEl = document.getElementById('output');
var currentContent = outputEl.innerHTML;
outputEl.innerHTML = message + '<br />' + currentContent;
console.log(message);
}
}
<template>
<h1>Contact</h1>
</template>
import { OutputService as console } from 'output-service';
export class Contact {
}
<template>
<h1>Products</h1>
<router-view></router-view>
</template>
import { OutputService as console } from 'output-service';
export class Products {
configureRouter(config, router) {
config.map([
{ route: '', redirect: 'Welcome' },
{ route: 'Welcome', name: 'Products-Welcome', moduleId: 'page-welcome' },
{ route: ':any/:id?', name: 'Products-Contact', moduleId: 'page-contact' }
]);
}
}
<template>
<h1>Welcome</h1>
</template>
import { OutputService as console } from 'output-service';
export class Welcome {
}
html, html *, html *:before, html *:after {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
font-family: sans-serif;
}
#content {
padding: 10px;
}
#menu {
background: #26418f;
color: white !important;
padding: 10px;
margin: 0;
}
#menu li {
display: inline-block;
}
#menu li + li {
margin-left: 10px;
border-left: 1px solid white;
padding-left: 10px;
}
#menu li a {
color: white;
text-decoration: none;
}
#output-wrapper {
padding: 0px 0 10px 10px;
border-top: 1px solid orange;
background: #FFFFA5;
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 150px;
font-family: Consolas;
}
#output-wrapper #output {
padding-top: 10px;
overflow-y: auto;
height: calc(100% - 30px);
}
#output-wrapper button {
position: absolute;
bottom: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment