- Aurelia - Best Practices
- Aurelia - Community
- Aurelia - Debugging
- Aurelia - Bundling
- Aurelia - Tools
- Aurelia - Localization
- Aurelia - Dialog
- Aurelia - Animations
- Aurelia - History
- Aurelia - Routing
- Aurelia - Refs
- Aurelia - HTTP
- Aurelia - Forms
- Aurelia - Event Aggregator
- Aurelia - Events
- Aurelia - Converters
- Aurelia - Binding Behavior
- Aurelia - Data Binding
- Aurelia - Plugins
- Aurelia - Configuration
- Aurelia - Dependency Injections
- Aurelia - Custom Elements
- Aurelia - Component Lifecycle
- Aurelia - Components
- Aurelia - First Application
- Aurelia - Environment Setup
- Aurelia - Overview
- Aurelia - Home
Aurelia Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Aurepa - Routing
Routing is an important part of every apppcation. In this chapter, you will learn how to use the router in Aurepa framework.
Step 1 - Create Pages
We have already created a components folder in one of the former chapters. If you don t have it created already, you should place it inside the src folder.
C:UsersusernameDesktopaurepaAppsrc>mkdir components
Inside this folder, we will create home and about directories.
C:UsersusernameDesktopaurepaAppsrccomponents>mkdir home C:UsersusernameDesktopaurepaAppsrccomponents>mkdir about
Inside the home folder, we need to create view and view-model files.
C:UsersusernameDesktopaurepaAppsrccomponentshome>touch home.js C:UsersusernameDesktopaurepaAppsrccomponentshome>touch home.html
We also need view and view-model for about page.
C:UsersusernameDesktopaurepaAppsrccomponentsabout>touch about.js C:UsersusernameDesktopaurepaAppsrccomponentsabout>touch about.html
Note − You can also create all the above folders manually.
Step 2 - Pages
Next, we need to add some default code to the files we created.
home.html
<template> <h1>HOME</h1> </template>
home.js
export class Home {}
about.html
<template> <h1>ABOUT</h1> </template>
about.js
export class About {}
Step 3 - Router
We will create view-model for router inside app.js file.
app.js
export class App { configureRouter(config, router) { config.title = Aurepa ; config.map([ { route: [ , home ], name: home , moduleId: ./components/home/home , nav: true, title: Home }, { route: about , name: about , moduleId: ./components/about/about , nav: true, title: About } ]); this.router = router; } }
Our router view will be placed in app.html.
app.html
<template> <nav> <ul> <p repeat.for = "row of router.navigation"> <a href.bind = "row.href">${row.title}</a> </p> </ul> </nav> <router-view></router-view> </template>
When we run the app, we will can change the routes by cpcking home or about pnks.
Advertisements