Skip to content

Instantly share code, notes, and snippets.

@jmezach
Last active August 27, 2018 08:49
Show Gist options
  • Save jmezach/b805a29cd56c07f4d3ba64f35d519a33 to your computer and use it in GitHub Desktop.
Save jmezach/b805a29cd56c07f4d3ba64f35d519a33 to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<router-view></router-view>
<button click.delegate="click()">Replace</button>
</template>
export class App {
configureRouter(config, router) {
this.router = router;
config.map([
{ route: ['', 'home'], name: 'home', moduleId: 'page' },
]);
}
click() {
console.log("Navigating");
this.router.navigate('home', { replace: true });
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jmezach.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jmezach.github.io/rjs-bundle/config.js"></script>
<script src="https://jmezach.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jmezach.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
<template>
<require from="./slot-component"></require>
<require from="./slot-item"></require>
<h1>Page</h1>
<slot-component>
<slot-item repeat.for="item of items">
</slot-item>
</slot-component>
</template>
import {activationStrategy} from 'aurelia-router';
export class Page {
message = 'Hello World!';
items = [{
title: "Item1",
content: "Item 1 Content",
subitems: [ "SubItem 1", "SubItem 2" ]
}, {
title: "Item2",
content: "Item 2 Content",
subitems: [ "SubItem 3", "SubItem 4" ]
}, {
title: "Item3",
content: "Item 3 Content",
subitems: [ "SubItem 5", "SubItem 6" ]
}]
determineActivationStrategy() {
return activationStrategy.replace;
}
bind() {
console.log("[page] bind");
}
attached() {
console.log("[page] attached");
}
detached() {
console.log("[page] detached");
}
unbind() {
console.log("[page] unbind");
}
}
<template>
<h2>Slot Component</h2>
<div>
<slot></slot>
</div>
</template>
export class SlotComponent {
bind() {
console.log("[slotcomponent] bind");
}
attached() {
console.log("[slotcomponent] attached");
}
detached() {
console.log("[slotcomponent] detached");
}
unbind() {
console.log("[slotcomponent] unbind");
}
}
<template>
<div><slot name="a"></slot></div>
<div><slot name="b"></slot></div>
</template>
export class SlotItem {
bind() {
console.log("[slot-item] bind()");
}
attached() {
console.log("[slot-item] attached()");
}
detached() {
console.log("[slot-item] detached()");
}
unbind() {
console.log("[slot-item] unbind()")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment