Pauan / rust-dominator

Zero-cost ultra-high-performance declarative DOM library using FRP signals for Rust!
MIT License
960 stars 62 forks source link

Add routing::replace_url #81

Closed TristanCacqueray closed 8 months ago

TristanCacqueray commented 8 months ago

Would it be acceptable to add a replace_url helper that uses history.replace instead of history.push, so that the current page is removed from the history?

Pauan commented 8 months ago

Sure, I think that's reasonable to have. I just hadn't added it since I didn't need it yet.

I've seen some websites abuse the history.replace which breaks the back button, so be sure to use it very sparingly. It's a very niche feature, not something that is used often.

TristanCacqueray commented 8 months ago

Great, I need this for my "create" route which can redirect to a "watch" route, and in that case, the back button should jump over the create page. FWIW, I used the fix in this commit: https://github.com/TristanCacqueray/logreduce/commit/1fe774c81db1d26785fe531b59af74615a4fe72c

TristanCacqueray commented 8 months ago

Looking at the code again, I would argue that calling routing::go_to_url directly insert history that may not match user clicks, so applications should use link! if possible.

Pauan commented 8 months ago

I would argue that calling routing::go_to_url directly insert history that may not match user clicks, so applications should use link! if possible.

The link! macro internally uses go_to_url, it's up to the application to choose how and when it calls go_to_url. Applications can shoot themself in the foot if they want to, dominator won't stop them.