Last active
February 20, 2018 05:10
-
-
Save 3cp/236566ed79f3d16de903447b53c3226b to your computer and use it in GitHub Desktop.
highlight "products" route menu when on "product/:id" page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .nav-bar { | |
| margin: 1rem; | |
| } | |
| .nav-bar a { | |
| margin: .5rem 1rem; | |
| padding: .5rem; | |
| font-size: 1.2rem; | |
| } | |
| .nav-bar a.active { | |
| outline: 4px solid blue; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template>Product #${id}</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class Product { | |
| activate(params) { | |
| this.id = params.id; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template>User #${id}</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class User { | |
| activate(params) { | |
| this.id = params.id; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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