优化路由检测

master
yutent 2023-11-15 18:27:22 +08:00
parent 66971278a2
commit e38f1c51dc
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "wkitd", "name": "wkitd",
"version": "1.3.0", "version": "1.3.1",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",
"files": [ "files": [

View File

@ -99,7 +99,7 @@ class Router {
let path = isHash let path = isHash
? hash ? hash
: location.href.replace(location.origin, '').replace(hash, '') : location.href.replace(location.origin, '').replace(hash, '')
let query let query = ''
if (path.includes('?')) { if (path.includes('?')) {
;[path, query] = path.split('?') ;[path, query] = path.split('?')
@ -107,6 +107,11 @@ class Router {
path = path.replace(PREFIX_REGEXP, '/') path = path.replace(PREFIX_REGEXP, '/')
if (!$view || path === this.#route.path) { if (!$view || path === this.#route.path) {
// query不同, 只更新query
if (query !== object2query(this.#route.query)) {
this.#route.query = query2object(query)
return this.#broadcast()
}
return return
} }