Vue router deletes query parameters
P粉947296325
P粉947296325 2023-09-02 17:34:15
0
1
582
<p>I'm using Nuxt2/Vue2 and I'm having trouble getting the query parameters when generating the website. </p> <p>I created my URL in the nuxt configuration by using an entry in Contentful like this: </p> <pre class="brush:php;toolbar:false;">generate: { crawler: false, async routes() { const items = ( await fetchEntriesByContentType({ contentType: "items" }) ).map(entry => { const routes = { route: `/items/item/${entry.fields.slug}`, payload: entry, } return routes; }); return items; } }</pre> <p>If I console log and try to debug in a Nuxt configuration file, it returns a url with parameters as expected, such as /items/item/101?type=book</p> <p>However, if I try to access it in my Vue component using this.$route.path, this.$route.fullPath or this.$route.query etc., it never returns after the "?" Any content. For example. For the example above it would always be /items/item/101</p> <p>Do I need to add something to the nuxt configuration to include query parameters? I noticed that if I click this.$route to go to the definition, it goes to the vue-router file in my node_modules even though I don't have vue-router installed. Is this causing the problem? </p>
P粉947296325
P粉947296325

reply all(1)
P粉978551081

You will not return anything in the map callback, assuming routes must be returned, it should look like this:

const items = (
    await fetchEntriesByContentType({ contentType: "items" })
).map(entry => {
    const routes = {
        route: `/items/item/${entry.fields.slug}`,
        payload: entry,
    }
    return routes;
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!