8000 $route updated too early when switching page · Issue #20674 · nuxt/nuxt · GitHub
[go: up one dir, main page]

Skip to content
$route updated too early when switching page #20674
@IlyaSemenov

Description

@IlyaSemenov

Environment

  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.4.3
  • Nitro Version: 2.3.3
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-wyu52r

  1. Click "Open in new tab"
  2. Open dev tools
  3. Click "bar" in the top menu
  4. See Vue warnings in console

Describe the bug

When a page is switched with <nuxt-link>, $route updates too early (before the old page unmounts). This leads to a whole bunch of bugs unless specifically treated.

In this reproduction, it emits Vue warnings when switching from foo to bar:

[Vue Router warn]: No match found for location with path "/bar/1"
[Vue Router warn]: No match found for location with path "/bar/2"
[Vue Router warn]: No match found for location with path "/bar/3"

because foo/index.vue was generating links with $route.path + "/${id}" and somehow it re-renders with the new $route before the page fully switches to bar.

Another example could be page watching $route.params and updating itself, which also crashes unless specifically handled.

This was not happening in Nuxt 2, and makes it difficult to port old apps.

Additional context

In this simple reproduction I could be generating static links with hardcoded prefix such as /foo/${id}, but that doesn't work for reusable components so it's not really an option.

The problem is broader than simply vue-router warnings. The old page should not re-render with the new $route at all!

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0