Skip to content

[FEATURE] A url generation method that returns the compiled url for the given named route populated with the given params. #1430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mutumarieru opened this issue May 17, 2017 · 5 comments
Labels

Comments

@mutumarieru
Copy link

What problem does this feature solve?

This feature will solve a simple problem, having urls in translations.
Today if i have a translation text that has anchors linking to some part of the website, i can't generate a url based on a named route.

"But you can just inject the url hardcoded" - well yes, but where's the point of having named routes if i can't generate my own url at some point to just have the "text value" of my url ?

Other use-case : a user has referral url he wants to share ton somebody, well i can't output the url to the user to copy / paste.

What does the proposed API look like?

@param Object options (the route options as for $router.push())
@param Boolean prependHostName (wether to prepend or not hostname)
@return String the url of the named route

this.$router.href([options], prependHostName)

e.g :

 this.$router.href({name: 'pages.policies'}) => /policies
 this.$router.href({name: 'pages.policies'}, true) => www.yourhostname.com/policies
@posva
Copy link
Member

posva commented May 17, 2017

You already have router.resolve: https://router.vuejs.org/en/api/router-instance.html
Isn't that what you're looking for?

@mutumarieru
Copy link
Author

@posva seems to be it

(the name wasn't so clear IMHO resolve looks more like word used to resolve data in this lib, maybe rename to resolveUrl ?)

could you tell what current?, append? params are for since it's not said on the docs

@mutumarieru
Copy link
Author

beforeResolve this method for example entertains the confusion on the router.resolve method lol

@posva
Copy link
Member

posva commented May 17, 2017

I agree that it's quite confusing, the resolve word is used a bit too much
I added a PR with the detail of those arguments, in short, you probably don't need them 😄

@posva posva added the docs label May 17, 2017
@mutumarieru
Copy link
Author

thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants