Vue-router: [feature] Passing an additional parameter not to be used in the URL

Created on 1 Apr 2016  ·  4Comments  ·  Source: vuejs/vue-router

I'm trying to call a dynamic route and I have this working really well but what i really need is to be able to pass an extra parameter to the template so that I can use that to specify a page type

for example:

v-link="{ path: "pagename" , params : (pageType : "page"}

is this possible?

I've done a work around using named routes but this is not good for me as I don't want the name of the route appearing in the URL I only want the page name.

Most helpful comment

What @fnlctrl said: what you are trying to "pass along" is not a URL param, but rather application state. A URL param is by definition part of the URL. You are actually trying to do two things: 1. navigate to the route 2. mutate the application state (pageType).

All 4 comments

Alias can be a solution for your example.
Here is a comment on another issue.
https://github.com/vuejs/vue-router/issues/235#issuecomment-201734131

Technically any parameter must be passed inside url.
For example, if clicking a link goes to /pagename whose 'type' is 'foo'.
What happens if the user refreshes the page after clicking? Now he hasn't clicked any link, there's no 'type' specified for the page.

If you do want to pass such 'invisible' parameter, use props.
<router-view :type="yourType">
And cache the type value using localStorage afterwards.

What @fnlctrl said: what you are trying to "pass along" is not a URL param, but rather application state. A URL param is by definition part of the URL. You are actually trying to do two things: 1. navigate to the route 2. mutate the application state (pageType).

Thank you guys.. I really couldn't see a way around the problem with out
passing a parameter. For most web apps using the named routes or parameters
in the url would be sufficient but I wanted clean simple URLs.

I will give the props a go and see how I fair with it and take this across
to support if I run into issues.

Thanks for the replies.
On Sat, 2 Apr 2016 at 07:36, Evan You [email protected] wrote:

Closed #444 https://github.com/vuejs/vue-router/issues/444.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/vuejs/vue-router/issues/444#event-612078703

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cnweibo picture cnweibo  ·  3Comments

saman picture saman  ·  3Comments

shinygang picture shinygang  ·  3Comments

rr326 picture rr326  ·  3Comments

Atinux picture Atinux  ·  3Comments