Q46. How to implement Routing in angular project?
Q47. What are angular router navigation events?
Q48. What are routing guards or Auth Guards?
Q49. What is redux for state management.
Q50. What is the use of ngRX?
--------------------------------------------------------------------------------------------------------------------------
Q46. How to implement Routing in angular project?
Answer 46:
In every angular application we have different components and evey component has its own view. To navigate to these different views we use routing.
1. Create a project with routing option enables. ng new newproj --routing
In below file first 9mins is the heart of logic.
https://www.youtube.com/watch?v=Nehk4tBxD4o
2. Above was to naviage with the url. If we want to navigate on click of a button we have to use routerLink on button
3. We have one routerLinkActive property. this will tell which router is active.
-----------------------------------------------------------------------------------------------------------------------
Q47. What are angular router navigation events?
Q48. What are routing guards or Auth Guards?
Q49. What is redux for state management.
Q50. What is the use of ngRX?
--------------------------------------------------------------------------------------------------------------------------
Q46. How to implement Routing in angular project?
Answer 46:
In every angular application we have different components and evey component has its own view. To navigate to these different views we use routing.
1. Create a project with routing option enables. ng new newproj --routing
- this above option will add a base tag <base href='/'/> in your index.html file.
- It will create a app-routing.module.ts- This file is the file where we will configure different routes. here we have const routes where we define path and component. We will export a routingComponent and import in app.module.ts (not required step)
- In future we are going to have new component we will not add it in app.module.ts file but in app-routing.module.ts file.
- it will import 'AppRoutingModule' in your app.moudule.ts file.
- it will add <router-outlet> tag in app.component.html file.
In below file first 9mins is the heart of logic.
https://www.youtube.com/watch?v=Nehk4tBxD4o
2. Above was to naviage with the url. If we want to navigate on click of a button we have to use routerLink on button
3. We have one routerLinkActive property. this will tell which router is active.
-----------------------------------------------------------------------------------------------------------------------
Q47. What are angular router navigation events?
Answer 47:
The sequence of router events is as follows:
Answer 47:
The sequence of router events is as follows:
- NavigationStart, - An event triggered when navigation starts.
- RouteConfigLoadStart, - An event triggered before the Router lazy loads a route configuration.
- RouteConfigLoadEnd, - An event triggered after a route has been lazy loaded.
- RoutesRecognized, - An event triggered when the Router parses the URL and the routes are recognized.
- GuardsCheckStart, - An event triggered when the Router begins the Guards phase of routing.
- ChildActivationStart, - An event triggered when the Router begins activating a route's children.
- ActivationStart, - An event triggered when the Router begins activating a route.
- GuardsCheckEnd, - An event triggered when the Router finishes the Guards phase of routing successfully.
- ResolveStart, - An event triggered when the Router begins the Resolve phase of routing.
- ResolveEnd, - An event triggered when the Router finishes the Resolve phase of routing successfuly.
- ActivationEnd - An event triggered when the Router finishes activating a route.
- ChildActivationEnd - An event triggered when the Router finishes activating a route's children.
- NavigationEnd, - An event triggered when navigation ends successfully.
- NavigationCancel, - An event triggered when navigation is canceled. This can happen when a Route Guard returns false during navigation, or redirects by returning a UrlTree.
- NavigationError,- An event triggered when navigation fails due to an unexpected error.
- Scroll - An event that represents a scrolling event.
--------------------------------------------------------------------------------------------------------------------------
Q48. What are routing guards or Auth Guards?
Answer 48:
Answer 48:
Angular’s route guards are interfaces which can tell the router whether or not it should allow navigation to a requested route. They make this decision by looking for a true or false return value from a class which implements the given guard interface.
There are 5 types of routing guards or Auth guards are available. We can implement angular authentication using routing guards.
- CanActivate: Controls if a route can be activated.
- CanActivateChild: Controls if children of a route can be activated.
- CanLoad: Controls if a route can even be loaded. This becomes useful for feature modules that are lazy loaded. They won’t even load if the guard returns false.
- CanDeactivate: Controls if the user can leave a route. Note that this guard doesn’t prevent the user from closing the browser tab or navigating to a different address. It only prevents actions from within the application itself
- Resolve: Performs route data retrieval before route activation.
Steps
1. Create a guard with statement and choose guards interface. better choose all.
ng g guard <guard-name>
It says when ever user has access to AdminGuardGuard. user can acces admin component.
Practical example of creating route guards
Must watch link
Good link below
--------------------------------------------------------------------------------------------------------------------------
Q49. What is redux for state management.
--------------------------------------------------------------------------------------------------------------------------
Q50. What is the use of ngRX?
--------------------------------------------------------------------------------------------------------------------------
Q50. What is the use of ngRX?
Answer:
ngrx is a set of RxJS -powered state management libraries for Angular, inspired by Redux, a popular and predictable state management container for JavaScript apps


