1

I have the following router.js with few dozens of value-x, i.e. value-one, value-2.

    const router = new Router({
        routes: [
            {
                path: "/plant/value-one",
                name: "value-one",
                components: {
                    default: Site
                },
                props: {
                    default: {
                        tab: 'value-one',
                        menu: 'value-one'
                    }
                }
            },
            {
                path: "/plant/value-two",
                name: "value-two",
                components: {
                    default: Site
                },
                props: {
                    default: {
                        tab: 'value-two',
                        menu: 'value-two'
                    }
                }
            }
        ]
    }
)

I would like to turn it into something like this:

path: "/plant/*"

I tried the following:

    const router = new Router({
        routes: [
            {
                path: "/plant/{:name}",
                name: name,
                components: {
                    default: Site
                },
                props: {
                    default: {
                        tab: name,
                        menu: name
                    }
                }
            }
        ]
    }
)

Name variable should also be passed to route's name as well as to tab and menu variables.

What am I missing here?

2
  • What is name? It doesn't appear to be defined Commented Oct 29, 2018 at 7:53
  • few dozens of value-x, example: value-one, value-two Commented Oct 29, 2018 at 7:59

1 Answer 1

1

I suggest to use children routes like this:

{
    path: '/plant',
    component: plantComponent,
    children: [
        {
            path: ':name',
            component: someComponent,
            name: 'someName'
        },

    ]
}

now any route after the plant/ can be defined as children of routes and i have defined a route :name which will be used for plant/* If you don't want to use children routes and just concerned with passing route parameters, use the parameter without the braces :

path: "/plant/:name",
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.