优化路由检测, 路由不存在时也触发回调, 行为与vue-router保持一致

master
yutent 2023-12-27 16:44:52 +08:00
parent fc20ea24d4
commit 9c9561cb1c
1 changed files with 8 additions and 1 deletions

View File

@ -23,6 +23,7 @@ class Router {
#ready = false #ready = false
#route = Object.create(null) #route = Object.create(null)
#tmp = null
#beforeEach #beforeEach
@ -133,7 +134,6 @@ class Router {
this.#exec(next) this.#exec(next)
}) })
} }
return this.#exec(next) return this.#exec(next)
} }
} }
@ -142,6 +142,11 @@ class Router {
$view.current = route.name $view.current = route.name
this.#route = { path, name: route.name, params: {}, query: {} } this.#route = { path, name: route.name, params: {}, query: {} }
this.#exec(this.#route) this.#exec(this.#route)
} else {
if (this.#tmp) {
this.#exec(this.#tmp)
this.#tmp = null
}
} }
} }
@ -215,6 +220,8 @@ class Router {
return return
} }
this.#tmp = obj
if (this.type === MODE_HASH) { if (this.type === MODE_HASH) {
if (replace) { if (replace) {
location.replace(path.replace(/^\//, '#/')) location.replace(path.replace(/^\//, '#/'))