Skip to content

Instantly share code, notes, and snippets.

@lstarky
Last active February 20, 2017 13:33
Show Gist options
  • Save lstarky/b6af53f1d63b9f580b8215f58661b879 to your computer and use it in GitHub Desktop.
Save lstarky/b6af53f1d63b9f580b8215f58661b879 to your computer and use it in GitHub Desktop.
Aurelia Router ViewPorts Demo
<template>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!--<div class="collapse navbar-collapse">-->
<ul class="nav navbar-nav">
<li repeat.for="row of router.navigation" class="${row.isActive ? 'active' : ''}">
<a href.bind="row.href">${row.title}</a>
</li>
</ul>
<!--</div>-->
</div>
</nav>
<div class="container-fluid">
<h1>Router Demo</h1>
<router-view name="left">LEFT</router-view>
<br><hr><br>
<router-view name="right">RIGHT</router-view>
</div>
</template>
export class App {
constructor() {
this.fname = "Liam";
}
configureRouter(config, router) {
config.title = 'Router ViewPorts Demo';
config.map([
{route: ['', 'home'], name: 'home', viewPorts: {left: {moduleId: './square'}, right: {moduleId: './circle'}}, nav: true, title: 'Home'},
{route: 'swap', name: 'swap', viewPorts: {left: {moduleId: './circle'}, right: {moduleId: './square'}}, nav: true, title: 'Swap'},
{route: 'circles', name: 'swap', viewPorts: {left: {moduleId: './circle'}, right: {moduleId: './circle'}}, nav: true, title: 'Circles'},
{route: 'squares', name: 'swap', viewPorts: {left: {moduleId: './square'}, right: {moduleId: './square'}}, nav: true, title: 'Squares'}
]);
this.router = router;
}
}
<template>
<h4>Circle</h4>
(View=${myView})
</template>
export class Circle {
activate(params, instr, extraConfig) {
this.myView = Object.keys(extraConfig.viewPortInstructions)[0];
console.log("Activate key", extraConfig);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body aurelia-app="main">
<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 function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(() => aurelia.setRoot());
}
<template>
<h4>Square</h4>
(View=${myView})
</template>
export class Square {
activate(params, instr, extraConfig) {
this.myView = Object.keys(extraConfig.viewPortInstructions)[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment