27 lines
685 B
JavaScript
27 lines
685 B
JavaScript
|
|
/**
|
|||
|
|
* 按 mp_config.mpUi 配置的路径跳转:Tab 页用 switchTab,其余 navigateTo
|
|||
|
|
*/
|
|||
|
|
const TAB_PATHS = [
|
|||
|
|
'/pages/index/index',
|
|||
|
|
'/pages/chapters/chapters',
|
|||
|
|
'/pages/match/match',
|
|||
|
|
'/pages/my/my'
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
function navigateMpPath(path) {
|
|||
|
|
if (!path || typeof path !== 'string') return false
|
|||
|
|
const full = path.trim()
|
|||
|
|
if (!full.startsWith('/')) return false
|
|||
|
|
const q = full.indexOf('?')
|
|||
|
|
const route = q >= 0 ? full.slice(0, q) : full
|
|||
|
|
const suffix = q >= 0 ? full.slice(q) : ''
|
|||
|
|
if (TAB_PATHS.includes(route)) {
|
|||
|
|
wx.switchTab({ url: route })
|
|||
|
|
return true
|
|||
|
|
}
|
|||
|
|
wx.navigateTo({ url: route + suffix })
|
|||
|
|
return true
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
module.exports = { navigateMpPath, TAB_PATHS }
|