[Vuejs]-How to add url to routes?

0👍

I think i get what you want to do, please tell me if I don’t.

You want to navigate to a component through a route, and give this route a "prop" which will be a character object is that it?

In this case, you can do this:

this.$router.push({
        name: 'NameOfYourRoute',
        params: {
        obj: nameOfYourObject
    },
});
//If your object is a component variable, don't forget the "this."

Then, in the display component, you can use this piece of code (in the "created()" method, to get your object:

//This will test if the object is correctly defined
if(!this.$route.params.obj){
            //Redirection if the object is incorrect
            this.$router.push('Redirection route')
        } else {
            this.character = this.$route.params.obj
            //Your code
}

Leave a comment