Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get full url (including origin) from route in VueJS?

Tags:

In this example:

const resolved = this.$router.resolve({
  name: 'about'
})

console.log(resolved.route.path)

Is it possible to get route with origin included? Like, if the url is site.com/about, the code would give /about, so I'll need to append origin myself: window.location.origin + resolved.route.path.

like image 611
Victor Avatar asked Apr 11 '20 07:04

Victor


People also ask

How do I get a full URL on vue?

js get Current Url Syntax: var currentUrl = window. location.

How can I get my old URL from vue?

from: Route : the current route being navigated away from. As an example you could use beforeRouteEnter , an in-component navigation guard, to get the previous route and store it in your data .. ... data() { return { ... prevRoute: null } }, beforeRouteEnter(to, from, next) { next(vm => { vm.

What is meta in route vue?

Sometimes, you might want to attach arbitrary information to routes like transition names, who can access the route, etc. This can be achieved through the meta property which accepts an object of properties and can be accessed on the route location and navigation guards.

How does routing work in vue JS?

Vue router: Vue Router helps link between the browser's URL/History and Vue's components allowing for certain paths to render whatever view is associated with it. A vue router is used in building single-page applications (SPA). The vue-router can be set up by default while creating your new project.


1 Answers

No, not from the router.

Even the router's base property is relative to the app root:

The base URL of the app. For example, if the entire single page application is served under /app/, then base should use the value "/app/".

$route.fullPath also begins at the app root. The docs describe it as:

The full resolved URL including query and hash.

like image 109
Dan Avatar answered Sep 19 '22 22:09

Dan