Home  >  Article  >  Web Front-end  >  How to get the current page route in Uniapp

How to get the current page route in Uniapp

coldplay.xixi
coldplay.xixiOriginal
2020-12-21 16:46:2114431browse

Uniapp’s method of getting the current page route: 1. Use getcurrentpages to get all arrays first, and get the last array, and then get the route; 2. Get the current page route directly, the code is [let curRoute = this. $mp.page.route;].

How to get the current page route in Uniapp

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.

Recommended (free): uni-app development tutorial

##Uniapp’s method of obtaining the current page route:

Method 1:

Use the official method getcurrentpages to get all the arrays first, then get the last array, and then get the route. Of course, there are other attributes that can be used, you can do it by yourself Print and view

let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
let curRoute = routes[routes.length - 1].route // 获取当前页面路由,也就是最后一个打开的页面路由

The following is the array object returned by the

getcurrentpages() method. Each object is actually the object of the opened page

How to get the current page route in Uniapp

Method 2:

Use the official

$mp variable to obtain it. In fact, it is basically the same as the above method, except that the method is mounted. In $mp

let curRoute  = this.$mp.page.route; // 直接获取当前页面路由

the following is the object returned by

this.$mp object, which is actually the webview object of the current page

How to get the current page route in Uniapp

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

Statement:
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