weapp.js
830 Bytes
/**
* @description 获取当前页路由(不含 query)
* @returns {string} 当前页 route,例如:pages/index/index
*/
const getCurrentPageUrl = () => {
// 获取加载的页面栈
const pages = getCurrentPages()
// 获取当前页面对象
const currentPage = pages[pages.length - 1]
// 当前页面 route(不含 query)
const url = currentPage.route
return url
}
/**
* @description 获取当前页 query 参数
* @returns {Object} 当前页 options(query 参数对象)
*/
const getCurrentPageParam = () => {
// 获取加载的页面栈
const pages = getCurrentPages()
// 获取当前页面对象
const currentPage = pages[pages.length - 1]
// 当前页面 query 参数对象
const options = currentPage.options
return options
}
export { getCurrentPageUrl, getCurrentPageParam }