Shonty
How to trigger createEffect when navigating to the same URL ?
It's a great idea but it doesn't seem to work
I found this solution where I navigate with
navigate(default_url, { state: reset_signal() });
and listen on location.state
in addition to location.search
, but it might have some weird edge case that I didn't think of. For instance, when I hit the browser back button, the createEffect run twice if I previously reset the buttons, but in this particular example, it still work as expected on the user interface
9 replies
How to trigger createEffect when navigating to the same URL ?
@FelipeEmos
To add some context to my question, I have a lot of buttons that act as filters used in the url. When I click on values of buttons, I store those values in a signal object, and when i click on the "Validate" button, it change the url params accordingly. I decided to listen to
location.search
in a createEffect so it plays nice with the browser back button and reduce overall code complexity. My problem here is when i click on the value of a button, and don't click on "Validate" button but I click on "Reset" button instead to put the default value, I navigate to the url with no query params. But if the url is already the one with no query params, it doesn t trigger the createEffect, and don t reset the value of the buttons I previously clicked.
I ask this question because there is an option similar with signal with const [something, set_something] = createSignal<string>('', { equals: false });
where you can trigger reactivity even if you set the same value
Here is a simplified code of my button component
A solution to my problem could be to change the url with a dummy path that is not the default url, and navigate back to the default url to trigger the createEffect, but it doesn't sound clean9 replies