NG Interview Set I - Routing Questions Flashcards
NG Interview Set I - Routing Questions
1
Q
What is the difference between RouterModule.forRoot() vs RouterModule.forChild()? Why is it important?
A
- forRoot is a convention for configuring app-wide Router service with routes, whereas forChild is for configuring the routes of lazy-loaded modules
2
Q
How does loadChildren property work?
A
- The Router calls it to dynamically load lazy loaded modules for particular routes
3
Q
When does a lazy loaded module get loaded?
A
- When its related route is first requested
4
Q
How would you use a Route Guard?
A
- You would implement CanActivate or CanDeactivate and specify that guard class in the route path you’re guarding
5
Q
What are some different types of RouteGuards?
A
- CanActivate, CanDeactivate, CanLoad, Resolve, etc.
6
Q
How would you intercept 404 errors in Angular 2?
A
- Can provide a final wildcard path like so:
{ path: ‘**’, component: PageNotFoundComponent }
7
Q
This link doesn’t work. Why? How do I fix it? ` < div routerLink=’ product.id ‘ > < /div > `
A
` < a [routerLink]= ” [’ product.id ’] ” > {{product.id}} < /a > `
8
Q
What do route guards return?
A
- boolean or a Promise/Observable resolving to boolean value
9
Q
What is < router-outlet >
for?
A
- Specifies the place where routes are mounted in the application