feat(router): 增加路由拦截器的query参数支持并优化路由处理
处理直接进入页面时传递query参数的情况,同时将路由处理逻辑从onLaunch移到onShow中
This commit is contained in:
10
src/App.vue
10
src/App.vue
@@ -5,11 +5,14 @@ import { tabbarStore } from './tabbar/store'
|
||||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
||||
|
||||
onLaunch((options) => {
|
||||
console.log('App Launch', options)
|
||||
})
|
||||
onShow((options) => {
|
||||
console.log('App Show', options)
|
||||
// 处理直接进入页面路由的情况:如h5直接输入路由、微信小程序分享后进入等
|
||||
// https://github.com/unibest-tech/unibest/issues/192
|
||||
console.log('App Launch', options)
|
||||
if (options?.path) {
|
||||
navigateToInterceptor.invoke({ url: `/${options.path}` })
|
||||
navigateToInterceptor.invoke({ url: `/${options.path}`, query: options.query })
|
||||
}
|
||||
else {
|
||||
navigateToInterceptor.invoke({ url: '/' })
|
||||
@@ -17,9 +20,6 @@ onLaunch((options) => {
|
||||
// 处理直接进入路由非首页时,tabbarIndex 不正确的问题
|
||||
tabbarStore.setAutoCurIdx(options.path)
|
||||
})
|
||||
onShow((options) => {
|
||||
console.log('App Show', options)
|
||||
})
|
||||
onHide(() => {
|
||||
console.log('App Hide')
|
||||
})
|
||||
|
||||
@@ -22,8 +22,9 @@ const isDev = import.meta.env.DEV
|
||||
export const navigateToInterceptor = {
|
||||
// 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
|
||||
// 增加对相对路径的处理,BY 网友 @ideal
|
||||
invoke({ url }: { url: string }) {
|
||||
// console.log(url) // /pages/route-interceptor/index?name=feige&age=30
|
||||
invoke({ url, query }: { url: string, query?: Record<string, string> }) {
|
||||
console.log(url) // /pages/route-interceptor/index?name=feige&age=30
|
||||
console.log(query) // /pages/route-interceptor/index?name=feige&age=30
|
||||
let path = url.split('?')[0]
|
||||
|
||||
// 处理相对路径
|
||||
|
||||
Reference in New Issue
Block a user