D
D
Daria It doesn't matter2021-10-11 16:41:26
Vue.js
Daria It doesn't matter, 2021-10-11 16:41:26

What is the correct way to make a vue-router route?

When working with vue-roter, I encountered a problem
, there is such a route

{
    path: "/news/:slug",
    name: "News",
    component: () => import( /* webpackChunkName: "promo" */ '../pages/News.vue'),
  }

json of this type comes from the back
{
"url": "/news/eksklyuzivy",
    "name": "Эксклюзивы",
    "type": 2,
    "icon": null,
    "slug": "article/eksklyuzivy"
},

I make a router link like this
<router-link
   :to="{
             name: 'News',
            params: { slug: 'article/eksklyuzivy' },
         }">Новини</router-link>

but at the output, the slash turns into% 2F and the url becomes like this news/article%2Feksklyuzivy
: in this case, it’s more correct to
ask that the back give the slug without article and add it to the route itself, or change the router link to this option
<router-link
          :to="{
                  path: '/article/eksklyuzivy',
                 }">Новини</router-link>

thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-10-11
@Aetae

All named parameters are escaped. If articleit does not carry any practical meaning, then it is logical to simply throw it away.
However, if you really need it, you can do this: path: "/news/*",- the asterisk is an exception and is not escaped.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question