Routing Flashcards
1
Q
How do you add routing to your Angular app, write down the steps.
A
- ng g module app-routing –flat –app=module
- Import RouterModule and Routes at top of app-routing file
- Add RouterModule and Routes to constructor
- Add RouterModule to imports with RouterModule.forRoot(routes) and just RouterModule to exports
- Create routes variable of type Routes set to an array with objects, where each object is a route, like so:
const routes: Routes = [
{ path: ‘/heroes’, component: HeroesComponent }
];
6. In a template add an routerLink attribute set to the path, so like so:
<a> </a>
2
Q
How do you set the root path for your routing? One way of doing it?
A
const routes: Routes = [
{ path: ‘’, rediretTo: ‘/dashboard’, pathMatch: ‘full’ }
];