redirectTo导致 diff undefined错误
想在进入页面的时候做统一的检测
App({ onLaunch() { const originalPage = Page Page = function (options, ...pageArgs) { const { onLoad } = options options.onLoad = function (onLoadOptions, ...args) { const user = wx.getStorageSync( 'user' ) const url = Utils.getCurrentPageUrl() // 如果用户未登录并且当前路径不是登录页面,则跳转到登录页面 if (!user && (url !== 'pages/auth/login' )) { wx.redirectTo({ url: 'pages/auth/login' }) } if (onLoad) { onLoad.call( this , onLoadOptions, ...args) } } originalPage(options, ...pageArgs) } } }) |
开发者工具报
如果url变成pages/auth/login则报路径的错误