Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Mini Program get the URL of the current page

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the "Mini Program how to get the current page URL" related knowledge, in the actual case operation process, many people will encounter such a dilemma, then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

Using getCurrentPages, you can get an array of all the page objects currently loaded, the last of which is the current page.

Var pages = getCurrentPages () / / get the loaded page var currentPage = pages [pages.length-1] / / get the object of the current page var url = currentPage.route / / current page url var options = currentPage.options / / if you want to obtain the parameters in url, you can view options and put it in utils as a tool function:

/ * get the current page url*/

Function getCurrentPageUrl () {

Var pages = getCurrentPages () / / get the loaded page

Var currentPage = pages [pages.length-1] / / get the object of the current page

Var url = currentPage.route / / current page url

Return url

}

/ * get the url*/ of the current page with parameters

Function getCurrentPageUrlWithArgs () {

Var pages = getCurrentPages () / / get the loaded page

Var currentPage = pages [pages.length-1] / / get the object of the current page

Var url = currentPage.route / / current page url

Var options = currentPage.options / / if you want to get the parameters in url, you can check options.

/ / parameters of stitching url

Var urlWithArgs = url +'?'

For (var key in options) {

Var value = options [key]

UrlWithArgs + = key +'='+ value +'&'

}

UrlWithArgs = urlWithArgs.substring (0, urlWithArgs.length-1)

Return urlWithArgs

}

Module.exports = {

GetCurrentPageUrl: getCurrentPageUrl

GetCurrentPageUrlWithArgs: getCurrentPageUrlWithArgs

}

This is the end of the content of "how Mini Program gets the current page URL". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report