Skip to content

Instantly share code, notes, and snippets.

@d13
Last active May 30, 2020 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save d13/946bc745d16ee7888e7bd069aed344e0 to your computer and use it in GitHub Desktop.
Save d13/946bc745d16ee7888e7bd069aed344e0 to your computer and use it in GitHub Desktop.
Aurelia Gist - nav in a LayoutView
<template>
<require from="nav-bar.html"></require>
<!-- this nav works -->
<nav-bar router.bind="router"></nav-bar>
<div class="page-host" style="margin-top:50px">
<router-view router.bind="router"></router-view>
</div>
</template>
export class App {
configureRouter(config, router) {
config.title = 'Aurelia';
config.map([
{
layoutView: 'layout-foo.html',
route: ['', 'welcome'],
name: 'welcome',
moduleId: 'module-home',
nav: true,
title: 'Welcome'
}//,
//{ layoutView: 'alt-layout.html', route: 'welcome2', name: 'welcome2', moduleId: 'welcome', nav: true, title: 'Welcome Alt Layout' },
]);
this.router = router;
}
}
<!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://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>
<template bindable="router">
<require from="nav-bar.html"></require>
<div>bar</div>
<!-- this nav does not work -->
<nav-bar router.bind="router"></nav-bar>
<div style="background-color:red;">
<slot name="main-content"></slot>
</div>
<div style="background-color:blue;">
<slot name="alt-content"></slot>
</div>
<div>baz</div>
</template>
<template>
<div slot="main-content">
hello world
</div>
<div slot="alt-content">
hello world 2
</div>
</template>
export class ModuleHome {
message = 'Hello World';
}
<template bindable="router">
<nav class="navbar navbar-light">
<div class="nav navbar-nav">
<span>Foo</span>
<a repeat.for="row of router.navigation" href.bind="row.href"
class="nav-item nav-link ${row.isActive ? 'active' : ''}">
${row.title}
</a>
</div>
</nav>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment