I am facing an issue in my Vue 3 application where I need to create a route for dynamic slugs. Currently, when using RouterLink
, the generated URL contains %2F
instead of actual slashes which is not the desired result.
For example, the current URL looks like this:
http://my.app/search/tool-based/1st-level%2F2nd-level%2F3rd-level
However, I want it to look like this:
http://my.app/search/tool-based/1st-level/2nd-level/3rd-level
Since the size of my slugs can vary and are unknown, hard-coding them is not a feasible solution as they could range from something short like /category/another
to extended paths such as
/category/another/another/another/another/another...
.
Below is my route configuration:
{
path: '/search/tool-based/:slug(.*)',
name: 'toolBasedSearch',
component: () => import('@/views/tool-search/ToolBasedSearchView.vue'),
},
Additionally, here is how I am using RouterLink (category.canonicalUrl
retrieved from the database appears in the format of category1/category2/category3...
):
<template>
<RouterLink
v-for="category in categories"
:to="{ name: 'toolBasedSearch', params: { slug: category.canonicalUrl } }"
:key="category.uuid!">
{{ category.namePlural }}
</RouterLink>
</template>