Home > Web Front-end > JS Tutorial > body text

How to get the currently activated route in vue

小云云
Release: 2018-03-19 10:31:00
Original
1982 people have browsed it

A route object (route information object) represents the status information of the currently activated route, including the information obtained by parsing the current URL, as well as the route records (route records) matched by the URL. The route object is immutable, and a new object is generated after each successful navigation. This article mainly shares with you a method for obtaining the current activated route in Vue. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.

route object appears in multiple places:

In the component, that is, this.$route

In the $route observer callback

The return value of router.match(location) (the currently activated routing information can be obtained in main.js)

Note:

## The path of #this.$route is different from the path of router.match(location). They both have an attribute fullpath, and the value is the concatenation of hash and path. In my case, router.match(location) is always equal to /login. , should point to the root route, and hash is the current routing path with the dot #. Therefore, to use router.match(location) to obtain the currently activated route, you can only use the hash attribute. The reason is not yet known. .

The above is the detailed content of How to get the currently activated route in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!