Render a new router and redirect in action of opened component doesn't redirect in the opened window
Example codes
why the redirect took places in the original window tab not in the opened window?
5 Replies
because everything is still being done in the original window, only the resulting html is being rendered in the new window.
Is this the browser default behavior? I thought I render a new router in side the window and a new router context was created.
<SomeComponent> lives under the existing router in the tree. So redirect() in the action used inside of <SomeComponent> is serviced by that router.
redirect() is imported from @solidjs/router which tells you it's not a browser function.Also note from the documentation that redirects are
thrown, not returned.
That way the router can catch the surrogate Response and process it (the practice of throwing and catching non-Errors is called a nonlocal return).
Is this the browser default behavior?In short yes. When you click a link in a document (i.e. navigate), the content of the response from
href replaces the current content of the window.
target="_blank" is necessary to force the link to open in a new window.MDN Web Docs
: The Anchor element - HTML: HyperText Markup Language | MDN
The HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.
I made a mistake in the above example. SomeComponent calls
createAsync instead of createAction(its not a post action).
I found the solution, I should not use the redirect in the server function ,just return the url and use location.replace with the new url.
Thanks!!