Skip to content

Instantly share code, notes, and snippets.

@3cp
Last active February 20, 2018 05:10
Show Gist options
  • Select an option

  • Save 3cp/236566ed79f3d16de903447b53c3226b to your computer and use it in GitHub Desktop.

Select an option

Save 3cp/236566ed79f3d16de903447b53c3226b to your computer and use it in GitHub Desktop.
highlight "products" route menu when on "product/:id" page
.nav-bar {
margin: 1rem;
}
.nav-bar a {
margin: .5rem 1rem;
padding: .5rem;
font-size: 1.2rem;
}
.nav-bar a.active {
outline: 4px solid blue;
}
<template>
<require from="./app.css"></require>
<div class="nav-bar">
<a
repeat.for="row of router.navigation"
href.bind="row.href"
class.bind="(row.isActive || row.config.name === highlight) ? 'active' : ''"
>${row.title}</a>
</div>
<hr>
<router-view></router-view>
</template>
import {computedFrom} from 'aurelia-framework';
export class App {
configureRouter(config, router) {
this.router = router;
config.title = "Demo";
config.map([
{
route: '', name: 'products', title: 'Products',
nav: true,
moduleId: './products.html'
},
{
route: 'users', name: 'users', title: 'Users',
nav: true,
moduleId: './users.html'
},
{
route: 'product/:id', name: 'product', title: 'Product',
moduleId: './product', settings: {highlight: 'products'}
},
{
route: 'user/:id', name: 'user', title: 'User',
moduleId: './user', settings: {highlight: 'users'}
},
]);
}
@computedFrom('router.currentInstruction')
get highlight() {
const inst = this.router.currentInstruction;
return inst && inst.config.settings.highlight;
}
}
<!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>Product #${id}</template>
export class Product {
activate(params) {
this.id = params.id;
}
}
<template>
<p><a route-href="route: product; params.bind: {id: 1}">product 1</a></p>
<p><a route-href="route: product; params.bind: {id: 2}">product 2</a></p>
</template>
<template>User #${id}</template>
export class User {
activate(params) {
this.id = params.id;
}
}
<template>
<p><a route-href="route: user; params.bind: {id: 1}">user 1</a></p>
<p><a route-href="route: user; params.bind: {id: 2}">user 2</a></p>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment