2

Essentially, I want to redirect to a dynamic URL, something like: /resource/:id, but I also want to pass some parameters at the same time. I don't want to go the query string route.

So, something like:

this.$router.push({path: 'resource/' + id, params: {
      test: "HELLO"
   }
});

The property gets passed when I have it like this (but it's not the right route)

this.$router.push({name: 'resource', params: {
      test: "HELLO"
   }
});

Is it possible to do what I want or do I need to start looking into VueEx?

2
  • What is your desired URL? domain.com/resource/100?test='HELLO'? Where 100 is the id Commented Apr 22, 2019 at 21:06
  • I don't want the querystring. I only want /resource/100 and the test would get passed behind the scenes. Commented Apr 22, 2019 at 21:11

2 Answers 2

3

You can do it like this:

your router:

{
    path: '/resource/:id',
    name: 'route-name',
    component: Component,
    props: true,
},

and in your component you can get all parameters as props:

props: ['id', 'name', '...'],

if you want to call the route in a router-link you can do it like this:

<router-link tag="a" :to="{name: 'route-name', params: {id: 1, name: 'John', ...}}">

I hope it would help you.

Sign up to request clarification or add additional context in comments.

2 Comments

I want to do it programatically though, not via a link (The button I'm having the user click needs to do an ajax call before redirecting).
I think it's not possible. but you can have some global computed variables. set them in you Ajax call and then call them in you destination component. If you want help doing that, let me know
0

I went the VueX route and set up a store. Doesn't look like it's possible to do what I was thinking initially.

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.