Skip to content

Instantly share code, notes, and snippets.

@lstarky
Last active February 16, 2017 02:19
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 lstarky/745b6792a07d92cbe7e9937020063260 to your computer and use it in GitHub Desktop.
Save lstarky/745b6792a07d92cbe7e9937020063260 to your computer and use it in GitHub Desktop.
Aurelia modify sidebar from router view
<template>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<ul class="nav navbar-nav">
<li><a href="#/home">Home</a></li>
<li><a href="#/square">Square</a></li>
<li><a href="#/circle">Circle</a></li>
</ul>
</div>
</nav>
<br><br><br><br><br><br><br>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2">
<sidebar></sidebar>
</div>
<div class="col-sm-10">
<h1>Hello, ${fname}</h1>
<hr>
Router view:
<router-view></router-view>
</div>
</div>
</div>
</template>
export class App {
constructor() {
this.fname = "Liam";
}
configureRouter(config, router) {
this.router = router;
config.title = 'Menu';
config.map([
{ route: ['', 'home'], name: 'home', moduleId: 'home' },
{ route: 'square', name: 'square', moduleId: 'square'},
{ route: 'circle', name: 'circle', moduleId: 'circle'}
]);
}
}
<template>
<h2>Circle</h2>
<button class="btn btn-success" click.delegate="onClick()">Set text</button>
</template>
import {inject} from 'aurelia-framework';
import {App} from './app';
@inject(App)
export class Circle {
constructor(app) {
this.app = app;
}
onClick() {
this.app.fname = 'Circle';
}
}
<template>
<h2>Home!</h2>
<button class="btn btn-default" click.delegate="onClick()">Set text from Home</button>
</template>
import {inject} from 'aurelia-framework';
import {App} from './app';
@inject(App)
export class Home {
constructor(app) {
this.app = app;
}
onClick() {
this.app.fname = 'Home';
}
}
<!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>
<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>-->
</body>
</html>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(() => aurelia.setRoot());
}
<template>
</template>
export class Sidebar {
}
<template>
<h2>Square</h2>
<button class="btn btn-primary" click.delegate="onClick()">Set text</button>
</template>
import {inject} from 'aurelia-framework';
import {App} from './app';
@inject(App)
export class Square {
constructor(app) {
this.app = app;
}
onClick() {
this.app.fname = 'Square';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment