Commit c4ea6a59 by 张立顺

fix 路由跳转处理

1 parent 29cc0abe
...@@ -2,6 +2,14 @@ const _routeHooks = Symbol('_routeHooks') ...@@ -2,6 +2,14 @@ const _routeHooks = Symbol('_routeHooks')
const _query = Symbol('_query') const _query = Symbol('_query')
const _routerList = Symbol('_routerList') const _routerList = Symbol('_routerList')
import util from '../utils/util.js' import util from '../utils/util.js'
/** 与 tabBar 等处一致:去掉前导 /、.html 后缀,避免开发与真机 path 形态不一致导致 find 失败 */
function normalizeRoutePath(p) {
if (p == null || p === '') return ''
return String(p)
.replace(/^\/+/, '')
.replace(/\.html$/i, '')
}
const generateRoutList = routerList => { const generateRoutList = routerList => {
let _routerList = routerList let _routerList = routerList
try { try {
...@@ -28,9 +36,17 @@ class Router { ...@@ -28,9 +36,17 @@ class Router {
wx.onAppRoute && wx.onAppRoute &&
wx.onAppRoute(e => { wx.onAppRoute(e => {
const thisPage = this.getPageInstance() const thisPage = this.getPageInstance()
const thisRouter = this[_routerList].find(item => item.url === `/${e.path}`) const routeKey = normalizeRoutePath(e.path)
// console.log(thisRouter) const thisRouter = this[_routerList].find(
if (thisRouter.isTab) { item => normalizeRoutePath(item.url) === routeKey
)
try {
const app = typeof getApp === 'function' ? getApp() : null
if (!thisRouter && app && app.globalData && app.globalData.routeDebug) {
console.warn('[router] onAppRoute 未命中', e.path, 'normalized:', routeKey)
}
} catch (err) { }
if (thisRouter?.isTab) {
wx.showTabBar({ wx.showTabBar({
success(result) { success(result) {
// console.log(result) // console.log(result)
......
export default __wxConfig.pages.map(item => ({ function collectWxPagePaths() {
const main = __wxConfig.pages || []
const subPkgs = __wxConfig.subPackages || __wxConfig.subpackages || []
const subPaths = subPkgs.flatMap(pkg => {
const root = (pkg.root || '').replace(/\/$/, '')
return (pkg.pages || []).map(p => {
const page = String(p || '').replace(/^\//, '')
return root ? `${root}/${page}` : page
})
})
return [...main, ...subPaths]
}
export default collectWxPagePaths().map(item => ({
url: `/${item}`, url: `/${item}`,
name: item.split('/').pop(), name: item.split('/').pop(),
parent: item.split('/')[0] parent: item.split('/')[0]
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!