简体   繁体   中英

Keep state when navating using RouterLink in Angular

I have the following link in my project that goes from a list of "Properties" to "Create property" form:

<button mat-button routerLink="../create-property" id="btn-new-property">+ Add property</button>

I use redux to manage my state and when I press on the link, I notice that the state of my application resets ie all the properties that were loaded are no longer there.

I am trying to understand what is the practice here? a) Shall I reload the properties from the service every time when a hit the list of "Properties"? b) Shall I be using something instead of RouterLink that keeps the state automatically?

I have looked at the suggestion in the documentation, which says that I can pass some state using [state] property on the link, but that seems weird that I would have to constantly pass the entire state from link to link.

My problem was that in the reducer I have not returned the state in the default case ieg

javascript
switch(action) {
//some cool reducers
default:
return state;

}```

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM