What are the benefits and disadvantages of using @ngrx/router-store instead of @angular/router?
The @ngrx/router-store exists so that it's possible for the store to be the single source of truth for an application's routing state. Without it, there would be application state - the current route - not represented in the store.
You will use NgRx to manage the state updates and user/server related events. You will create two Stores for our application: menus: to manage menu related functionalities (CRUD operations) user: to manage user-related functionalities such as authentication using Auth0.
When should you not use NgRx? Never use NgRx if your application is a small one with just a couple of domains or if you want to deliver something quickly. It comes with a lot of boilerplate code, so in some scenarios it will make your coding more difficult.
The NgRx Store is a Redux-inspired state management system that enables you to use observables to manage state in an Angular application. The primary advantage to using the NgRx Store is the ability to store all state in a single tree that is accessible from any part of the application.
Here is a comparison to the now deprecated beta router https://gitter.im/ngrx/store?at=5710e4fc5cd40114649b9399
the main differences between the component router and ngrx/router are the decisions behind the design. The component router takes a more internal approach when it comes to components if you look at the lifecycle hooks. Our router doesn’t require that the router hook into your components so any component is routable. Another difference is the use of observables. The component router uses promises to handle its lifecycle, whereas ours uses observables because they lend themselves to more of a reactive approach. Our route/query parameters are observable which makes reusing components when parameters change easier. Our router has more streams available for you to subscribe to and react upon. The overall idea is that the browser URL itself is a stream and we are turning that stream into a view of rendered routes. Both routers have a concept of lazy loading, protecting routes, resolving data and lifecycle events. Both still have gaps that need to be filled. If you prefer a more observable approach, our router works very nicely with that.
The new angular2 router will be alot closer to what ngrx/router is today, so if you are using the deprecated beta router now, stay on that until the new router is released and then migrate. If you were starting from nothing, I'd say use ngrx/router because it provides a relatively easy migration path to the new router once its ready.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With