Routing Flashcards

1
Q

How do you add routing to your Angular app, write down the steps.

A
  1. ng g module app-routing –flat –app=module
  2. Import RouterModule and Routes at top of app-routing file
  3. Add RouterModule and Routes to constructor
  4. Add RouterModule to imports with RouterModule.forRoot(routes) and just RouterModule to exports
  5. 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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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’ }
];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly