Use Regex in Vue Router Paths

后端 未结 1 939
[愿得一人]
[愿得一人] 2020-12-20 18:13

I am creating a VueJS app which heavily uses the vue router.

Here\'s the structure of my routes.js:

export const routes = [
    { path:          


        
相关标签:
1条回答
  • 2020-12-20 18:45

    vue-router uses path-to-regexp as its path matching engine, so it supports many advanced matching patterns such as optional dynamic segments, zero or more / one or more requirements, and even custom regex patterns.

    So change your route definition as follows:

    { path: 'poetry/:id(\\d+)', name: 'poetrycard', component: PoetryCard }
    

    Reference- Advanced Matching patterns

    0 讨论(0)
提交回复
热议问题