Nuxt.js: Page mounted twice on redirect in SPA

Created on 25 Oct 2018  路  6Comments  路  Source: nuxt/nuxt.js

Version

v2.2.0

Reproduction link

https://codesandbox.io/s/40y7x1l0p4

Steps to reproduce

  1. Open reproduction link
  2. Open console
  3. Add /random_string to the codesandbox project url like this https://40y7x1l0p4.sse.codesandbox.io/randome_string

What is expected ?

Inside the console the String test should only exist once.

What is actually happening?

The string test will be shown twice.

Additional comments?

I just added a middleware that redirects to the test page if it is not in the router array:

export default ({ app, route, redirect }) => {
  const { path, query } = route;
  const { routes } = app.router.options;
  // Other redirects
  if (routes.find(value => value.path === path) === undefined) {
    return redirect("/test");
  }
};

Inside the test page i only output test on the mounted event.
This only occure when the nuxt mode is set to spa

This bug report is available on Nuxt community (#c8038)
bug-report stale

Most helpful comment

Dam Automatic bot. It's still relevant in v2.3.4. Please reopen this.

All 6 comments

I have a same issue

asyncadata/fetch trigger only once in this case.
mounted and created twice. so component got created twice for some reason
Happens in production mode too

I can also confirm this bug. If I wrap the redirect in a setTimeout(() => redirect()) it fixes the bug. But this is definitely a bug and a serious on eat that.

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as 馃晲Pending will not be automatically marked as stale.

Dam Automatic bot. It's still relevant in v2.3.4. Please reopen this.

Because there is no response from the nuxt team i opened a new ticket for it: https://github.com/nuxt/nuxt.js/issues/4757

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vadimsg picture vadimsg  路  3Comments

shyamchandranmec picture shyamchandranmec  路  3Comments

msudgh picture msudgh  路  3Comments

danieloprado picture danieloprado  路  3Comments

lazycrazy picture lazycrazy  路  3Comments