Feature Request
* ngxs: 3.2.0
* @angular/core: 6.1.2
Since we are moving most of the logic to the store and we have the router state integrated in the root state, we should consider accessing the route params from within the actions, something like this
```ts
@Action(ViewUser)
onViewUser(ctx: StateContext
const uid = this.store.selectSnapshot(state => state.router.params['id']);
const collection = this.store.selectSnapshot(state => state.users.collection.data);
// Check if user already exists in the collection
if (collection[uid]) {
ctx.patchState({
user: collection[uid],
error: null
});
} else {
// Otherwise fetch the user from the database
return ctx.dispatch(new GetUser(uid));
}
}
### Observed behavior
Currently the route params is located very deep
```ts
const uid = this.store.selectSnapshot(state => state.router.state.root.firstChild.firstChild.params['id']);
// or
const uid = this.store.selectSnapshot(state => state.router.state.root.children[0].children[0].params['id']);
const uid = this.store.selectSnapshot(state => state.router.params['id']);
// or
const uid = this.store.selectSnapshot(state => state.router.state.root.params['id']);
It would be a great if we can refactor the router state and make it more friendly and flattened
You can write your own custom router serializer, just like the new example in the docs:
https://ngxs.gitbook.io/ngxs/plugins/router#custom-router-state-serializer
@eranshmil This is exactly what I was looking for!
Most helpful comment
You can write your own custom router serializer, just like the new example in the docs:
https://ngxs.gitbook.io/ngxs/plugins/router#custom-router-state-serializer