How does Mini Program get the URL of the current page
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!