[SPA] Redirect to external URL from asyncData replaces current history entry #5032
Comments
|
Non-ideal workaround would be to trigger redirect from a short timeout. Not ideal because the And of course there is always an option of not using nuxt-link for those URLs but that is not always possible to control. |
|
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
|
reproducible |
|
Redirect function now is useless in Nuxt.js, because of this bug. Any updates? |
|
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
|
go away stale bot |
|
Have there been any issues opened for this? Is there a fix? |
|
@rchl I know this is an old issue but it seems history it not working at all in this example? When clicking |
|
@TimvdEijnden You need to export to zip from codesandbox. |
|
@rchl Use <template>
<h1>Redirecting...</h1>
</template>
<script>
export default {
middleware ({ redirect }) {
return redirect('https://elg.no');
},
}
</script>But yeah, still the same problem :( |


Version
v2.4.3
Reproduction link
https://codesandbox.io/s/8yl9852pv9
Steps to reproduce
pages/fail.vuewith:pages/redirect.vuewith:pages/index.vuewith:What is expected ?
Return to the index page where link was clicked from.
What is actually happening?
Navigates to /fail page
Additional comments?
What happens is, when navigating in SPA mode, the code that handles redirect() call is using
location.replaceto navigate to external URL. The problem is that that happens while URL is still set to/so it replaces that navigation entry with external URL. Navigating back thus goes back to page visited before/which is unexpected.The solution would be to either allow the URL to change
/redirectand then triggerlocation.replaceor uselocation.assigninstead. Former is probably more risky as it would trigger extra routing events and potentially some more code that could possibly fail.This is only an issue with redirects to external URLs.
The text was updated successfully, but these errors were encountered: