Navigation and Routing Basics Flashcards
Selector property is only required if
component will be nested within another component
What Router module does?
Registers the router service. Declares the router directives. Exposes configured routes.
Route is defined
by route definitions
Router link directive is an
attribute directive.
When a route is activated associated component is displayed. But where?
By directive router-outlet’. Component is displayed inside.
What to do to pass parameters to a route?
Add parameters to route. Add router link to anchor tag and add values to the link parameters array. First value is string path of the route. Second value is for the route parameter. When route composes the URL it uses the parameter.
To get paramter from URL
Use ActivatedRoute service do get parameter.
Reading parameters from route can be done in two ways.
One, if route parameter doesn’t change - use snapshot.paramMap.
Second, use observable to read parameters if they change - use paramMap…
what is ? in product?.name
Safe navigation operator.. like in c#
How to activate a route with code?
Use Router service. The method is .navigate([‘/products’]);
What types of Route Guards there are
CanActivate - guard navigation to a route
CanDeactivate - guard navigation from a foute
Resolve - Pre-fetch data before activating a route
CanLoad - Prevent asynchronous routing
What is a route guard
A service. Use @Injectable
How to use the route guard
Add the guard to the route in the route definitions
Angular supports union of types or passing/returning multiple types at ones.
True story.