Commit 6c091b7f by 李伟康

修复路由方法

1 parent 55dfdcb6
...@@ -2,8 +2,7 @@ const _routeHooks = Symbol('_routeHooks') ...@@ -2,8 +2,7 @@ const _routeHooks = Symbol('_routeHooks')
const _query = Symbol('_query') const _query = Symbol('_query')
const _routerList = Symbol('_routerList') const _routerList = Symbol('_routerList')
import { import {
generateRoutList, generateRoutList
wxOnAppRouteFn
} from './wxOnAppRoute.js' } from './wxOnAppRoute.js'
import { import {
getNavigationBarTitleText getNavigationBarTitleText
...@@ -80,11 +79,14 @@ class Router { ...@@ -80,11 +79,14 @@ class Router {
/**只传页面名 默认跳转当前包下的页面,相同名称默认第一个 */ /**只传页面名 默认跳转当前包下的页面,相同名称默认第一个 */
if (!_name && !last_name) name = _parent if (!_name && !last_name) name = _parent
const routerMapItem = this[_routerList].find(item => { const routerMapItem = this[_routerList].find(item => {
if (route.includes('/')) return item.url === route
else {
if (last_name) { if (last_name) {
return item.parent === parent && item.name === last_name && item.subPages === name return item.parent === parent && item.name === last_name && item.subPages === name
} else { } else {
return item.parent === parent && item.name === name return item.parent === parent && item.name === name
} }
}
}) })
if (!routerMapItem) { if (!routerMapItem) {
console.error('找不到路由') console.error('找不到路由')
...@@ -172,7 +174,6 @@ class Router { ...@@ -172,7 +174,6 @@ class Router {
if (Object.keys(data).length !== 0) data.on('getData', res => callBack(res)) if (Object.keys(data).length !== 0) data.on('getData', res => callBack(res))
} }
onRoute(fn) { onRoute(fn) {
console.log(fn)
this[_routeHooks].push(fn) this[_routeHooks].push(fn)
return () => { return () => {
const i = list.indexOf(fn) const i = list.indexOf(fn)
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
/**处理前置钩子逻辑 */ /**处理前置钩子逻辑 */
const routerBefore = (next) => { const routerBefore = (next) => {
// console.log("处理前置钩子逻辑"); // console.log("处理前置钩子逻辑");
next(); next();
}; };
/**处理后置钩子逻辑 */ /**处理后置钩子逻辑 */
......
...@@ -17,27 +17,6 @@ import { ...@@ -17,27 +17,6 @@ import {
* @param {*} obj.setNavigationBarTitleText * @param {*} obj.setNavigationBarTitleText
* @param {*} obj.getRouterList * @param {*} obj.getRouterList
*/ */
/**有问题,query一直为空 */
export const wxOnAppRouteFn = (obj,a) => {
wx.onAppRoute &&
wx.onAppRoute(e => {
let thisPage = obj.getPageInstance()
if (thisPage) {
obj.setNavigationBarTitleText(thisPage)
let onRoute = thisPage.onRoute
typeof onRoute === 'function' && onRoute(obj.query)
}
obj.routeHooks.forEach(fn => {
try {
typeof fn === 'function' && fn(e, obj.query, obj.routerList)
} catch (err) {
console.log(err)
}
})
obj.query = {}
})
}
/** /**
* 生成特定格式路由 * 生成特定格式路由
* *
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!