How do I do something after a redirect, like reload the page, or in this case reconnect a websocket?
there is no redirect reload, or some kind of hook that gets called after a redirect has happened to the same dynamic route with different params.
8 Replies
Couldn't you use
onMount()
or createEffect()
on the page you are redirecting to?
Basically, when this page loads, check for a websocket connection. If it exists, return. If not, reconnect.I have this dynamic route u/:username
The action changes the username invalidates the user and redirects to
u/hello to u/world , and I can't get any notification on anywhere.
Except onBeforeLeave occurs but I get the old username 'hello'.
I need a callback after the cache invalidates, so I can reconnect the websocket.
I think you'll have to recall your getUser function on each load. Or store the current user name. Then check it on page load. If the user name is the same, proceed. But if the user name has changed, rerun getUser.
You could use
useParams
https://github.com/solidjs/solid-router/tree/main?tab=readme-ov-file#useparamsGitHub
GitHub - solidjs/solid-router: A universal router for Solid inspire...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router
in an effect to see when the param has changed and do the changes
useParams doesn't react to changes, I've also used a custom signal and tried to change that and it gave error, set_a is not defined.
Does this effect log the changes to the username if you add it?
omg that worked thanks.