Skip to content

Instantly share code, notes, and snippets.

@dtaalbers
Last active September 28, 2016 11:55
Show Gist options
  • Save dtaalbers/90694ea76d99f9a3067c8e3d63b3e1b4 to your computer and use it in GitHub Desktop.
Save dtaalbers/90694ea76d99f9a3067c8e3d63b3e1b4 to your computer and use it in GitHub Desktop.
Routes example
<template>
<router-view></router-view>
</template>
import { inject } from 'aurelia-framework';
import { Router } from 'aurelia-router';
@inject()
export class App {
router = null;
routes = [
{ route: 'page', name: 'page', moduleId: './page' }
];
constructor(router) {
this.router = router;
this.router.addRoute({ route: 'home', name: 'Home', moduleId: './home' });
this.router.addRoute({ route: '', name: 'Home', moduleId: './home' })
}
addRoute(name){
if (this.router.hasRoute(name)) return;
let route = this.getRoute(name);
this.router.addRoute(route);
}
getRoute(name: string): any {
return this.routes.find(r => r.name == name);
}
}
<template>
<h1>${title}</h1>
<button class="btn btn-primary" click.delegate="navigateTo('page')">Go to page</button>
</template>
import {inject} from 'aurelia-framework';
import {Router} from 'aurelia-router';
@inject(Router)
export class Home {
router = null;
constructor(router) {
this.router = router;
}
navigateTo(route) {
this.router.navigateToRoute(route);
}
title = 'Home page';
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body aurelia-app="main" class="container">
<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 function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.plugin('aurelia-validation');
aurelia.start().then(() => aurelia.setRoot());
}
<template>
<h1>${message}</h1>
</template>
export class Page {
message = 'Page';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment