bug fix
This commit is contained in:
parent
d3d87ca68e
commit
48c09f401b
55
main_UI.js
55
main_UI.js
@ -394,49 +394,48 @@ class Router {
|
|||||||
/**
|
/**
|
||||||
* @param {string} route
|
* @param {string} route
|
||||||
*/
|
*/
|
||||||
async routeTo(path) {
|
handleRouting = async (page) => {
|
||||||
|
if (this.routingStart) {
|
||||||
|
this.routingStart(this.state)
|
||||||
|
}
|
||||||
|
if (this.routes[page]) {
|
||||||
|
await this.routes[page](this.state)
|
||||||
|
this.lastPage = page
|
||||||
|
} else {
|
||||||
|
if (this.routes['404']) {
|
||||||
|
this.routes['404'](this.state);
|
||||||
|
} else {
|
||||||
|
console.error(`No route found for '${page}' and no '404' route is defined.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.routingEnd) {
|
||||||
|
this.routingEnd(this.state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async routeTo(destination) {
|
||||||
try {
|
try {
|
||||||
let page
|
let page
|
||||||
let wildcards = []
|
let wildcards = []
|
||||||
let queryString
|
let params = {}
|
||||||
let params
|
let [path, queryString] = destination.split('?');
|
||||||
[path, queryString] = path.split('?');
|
|
||||||
if (path.includes('#'))
|
if (path.includes('#'))
|
||||||
path = path.split('#')[1];
|
path = path.split('#')[1];
|
||||||
if (path.includes('/'))
|
if (path.includes('/'))
|
||||||
[, page, ...wildcards] = path.split('/')
|
[, page, ...wildcards] = path.split('/')
|
||||||
else
|
else
|
||||||
page = path
|
page = path
|
||||||
this.state = { page, wildcards, lastPage: this.lastPage }
|
this.state = { page, wildcards, lastPage: this.lastPage, params }
|
||||||
if (queryString) {
|
if (queryString) {
|
||||||
params = new URLSearchParams(queryString)
|
params = new URLSearchParams(queryString)
|
||||||
this.state.params = Object.fromEntries(params)
|
this.state.params = Object.fromEntries(params)
|
||||||
}
|
}
|
||||||
if (this.routingStart) {
|
if (document.startViewTransition) {
|
||||||
this.routingStart(this.state)
|
|
||||||
}
|
|
||||||
if (this.routes[page]) {
|
|
||||||
// Fallback for browsers that don't support View transition API:
|
|
||||||
if (!document.startViewTransition) {
|
|
||||||
await this.routes[page](this.state)
|
|
||||||
this.lastPage = page
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// With a transition:
|
|
||||||
document.startViewTransition(async () => {
|
document.startViewTransition(async () => {
|
||||||
await this.routes[page](this.state)
|
await this.handleRouting(page)
|
||||||
this.lastPage = page
|
})
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if (this.routes['404']) {
|
// Fallback for browsers that don't support View transition API:
|
||||||
this.routes['404'](this.state);
|
await this.handleRouting(page)
|
||||||
} else {
|
|
||||||
console.error(`No route found for '${page}' and no '404' route is defined.`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.routingEnd) {
|
|
||||||
this.routingEnd(this.state)
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|||||||
2
main_UI.min.js
vendored
2
main_UI.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user