Commit 6c091b7f by 李伟康

修复路由方法

1 parent 55dfdcb6
......@@ -2,8 +2,7 @@ const _routeHooks = Symbol('_routeHooks')
const _query = Symbol('_query')
const _routerList = Symbol('_routerList')
import {
generateRoutList,
wxOnAppRouteFn
generateRoutList
} from './wxOnAppRoute.js'
import {
getNavigationBarTitleText
......@@ -80,10 +79,13 @@ class Router {
/**只传页面名 默认跳转当前包下的页面,相同名称默认第一个 */
if (!_name && !last_name) name = _parent
const routerMapItem = this[_routerList].find(item => {
if (last_name) {
return item.parent === parent && item.name === last_name && item.subPages === name
} else {
return item.parent === parent && item.name === name
if (route.includes('/')) return item.url === route
else {
if (last_name) {
return item.parent === parent && item.name === last_name && item.subPages === name
} else {
return item.parent === parent && item.name === name
}
}
})
if (!routerMapItem) {
......@@ -172,7 +174,6 @@ class Router {
if (Object.keys(data).length !== 0) data.on('getData', res => callBack(res))
}
onRoute(fn) {
console.log(fn)
this[_routeHooks].push(fn)
return () => {
const i = list.indexOf(fn)
......
......@@ -5,7 +5,6 @@
/**处理前置钩子逻辑 */
const routerBefore = (next) => {
// console.log("处理前置钩子逻辑");
next();
};
/**处理后置钩子逻辑 */
......@@ -33,4 +32,4 @@ Page = function (options) {
OldPage(options);
};
export default routerBefore;
export default routerBefore;
\ No newline at end of file
......@@ -17,27 +17,6 @@ import {
* @param {*} obj.setNavigationBarTitleText
* @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!