Giter Site home page Giter Site logo

Comments (10)

danielroe avatar danielroe commented on June 3, 2024 2

The issue comes from vue-router and suspense - we need to ensure that within each suspense fork we have different route objects. We in fact even do custom handling within <template> (injecting a custom route object) and for useRoute...

We probably need to port this fix to this.$route as well, if possible.

from nuxt.js.

jakubednar avatar jakubednar commented on June 3, 2024 1

Just found out that this.$route inside computed is getting triggered twice. Added console.log there while debugging.
2024-05-21 10 17 13

from nuxt.js.

jakubednar avatar jakubednar commented on June 3, 2024 1

I did something similar, but i got error thatthis is undefined. But I did it with dynamic regex which supported both ctx and this cases. I'm going to try to handle just this.$route case.

from nuxt.js.

RodrigoProjects avatar RodrigoProjects commented on June 3, 2024 1

Thanks for making the PR for me @jakubednar time saver! <3

from nuxt.js.

stackblitz avatar stackblitz commented on June 3, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from nuxt.js.

jakubednar avatar jakubednar commented on June 3, 2024

Hello 👋, I started working on this issue, but I got a little stuck. I didn't manage to make it work, but from investigation it looks like this.$route inside computed is not waiting for page:finish hook and it gets the new route object right away.

from nuxt.js.

danielroe avatar danielroe commented on June 3, 2024

@jakubednar This might help. It's how we ensure that we use the provided route rather than this.$route:

if (!INJECTION_SINGLE_RE.test(code) || code.includes('_ctx._.provides[__nuxt_route_symbol')) { return }
let replaced = false
const s = new MagicString(code)
s.replace(INJECTION_RE, () => {
replaced = true
return '(_ctx._.provides[__nuxt_route_symbol] || _ctx.$route)'
})
if (replaced) {
s.prepend('import { PageRouteSymbol as __nuxt_route_symbol } from \'#app/components/injections\';\n')
}

from nuxt.js.

RodrigoProjects avatar RodrigoProjects commented on June 3, 2024

I could create a Vue plugin and overwrite the $route with the Nuxt provided route. What you think of this as potential fix? @danielroe

Doing a replace like you did will be hard for this case when using options API

from nuxt.js.

jakubednar avatar jakubednar commented on June 3, 2024

I tried fixing it yesterday, but all I managed to affect was useRoute, $route inside template. Maybe I'm doing something wrong, but I couldn't affect this.$route inside script.
I will be grateful for any help with this.

from nuxt.js.

RodrigoProjects avatar RodrigoProjects commented on June 3, 2024

I tried fixing it yesterday, but all I managed to affect was useRoute, $route inside template. Maybe I'm doing something wrong, but I couldn't affect this.$route inside script. I will be grateful for any help with this.

After further investigation, I think you can do something like this:
`js
const INJECTION_RE = /\bthis.$route\b/g
if (!INJECTION_SINGLE_RE.test(code) || code.includes('ctx..provides[__nuxt_route_symbol')) { return }

let replaced = false
const s = new MagicString(code)
s.replace(INJECTION_RE, () => {
replaced = true
return '(this._.provides[__nuxt_route_symbol] || this.$route)'
})
if (replaced) {
s.prepend('import { PageRouteSymbol as __nuxt_route_symbol } from '#app/components/injections';\n')
} `

Did this very fast but I think you get the general idea, do a replace for this.$route too and inject the "nuxt route" and fallback to this.$route like daniel did for the _ctx case!

from nuxt.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.