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

How to get the currently activated route in vue

亚连
Release: 2018-05-29 17:01:42
Original
1896 people have browsed it

Below I will share 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.

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.

Route object is immutable, and a new object will be generated after each successful navigation.

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 what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Solve the problem of failure after using vue.js routing

How to perfectly parse data in js

DOM event binding analysis in js

##

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