mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
fix(router): broken query string matching
This commit is contained in:
parent
f0698d7dd6
commit
aa162b2edb
1 changed files with 7 additions and 7 deletions
|
@ -49,7 +49,7 @@ export default class Router {
|
|||
return this.activateRoute(this.homeRoute)
|
||||
}
|
||||
|
||||
const matched = this.tryMatchRoute(location.hash)
|
||||
const matched = this.tryMatchRoute()
|
||||
const [route, params] = matched ? [matched.route, matched.params] : [null, null]
|
||||
|
||||
if (!route) {
|
||||
|
@ -68,16 +68,16 @@ export default class Router {
|
|||
return this.activateRoute(route, params)
|
||||
}
|
||||
|
||||
private tryMatchRoute (hash: string) {
|
||||
if (!this.cache.has(hash)) {
|
||||
private tryMatchRoute () {
|
||||
if (!this.cache.has(location.hash)) {
|
||||
for (let i = 0; i < this.routes.length; i++) {
|
||||
const route = this.routes[i]
|
||||
const matches = hash.match(new RegExp(`^#!?${route.path}/?(?:\\?(.*))?$`))
|
||||
const matches = location.hash.match(new RegExp(`^#!?${route.path}/?(?:\\?(.*))?$`))
|
||||
|
||||
if (matches) {
|
||||
const searchParams = new URLSearchParams(new URL(location.href.replace(/#!?\?/, '')).search)
|
||||
const searchParams = new URLSearchParams(new URL(location.href.replace('#/', '')).search)
|
||||
|
||||
this.cache.set(hash, {
|
||||
this.cache.set(location.hash, {
|
||||
route,
|
||||
params: Object.assign(Object.fromEntries(searchParams.entries()), matches.groups || {})
|
||||
})
|
||||
|
@ -87,7 +87,7 @@ export default class Router {
|
|||
}
|
||||
}
|
||||
|
||||
return this.cache.get(hash)
|
||||
return this.cache.get(location.hash)
|
||||
}
|
||||
|
||||
public async triggerNotFound () {
|
||||
|
|
Loading…
Reference in a new issue