This commit is contained in:
熊潇 2025-01-07 02:58:02 +08:00
parent c855c7d3d5
commit 01db9c9ea2

View File

@ -54,6 +54,7 @@ export class Page {
this.listen();
}
}
popstate(event?: PopStateEvent, manualOpts?: { id?: string; type: 'singal' | 'all'; pathname?: string }) {
const pathname = manualOpts?.pathname ?? window.location.pathname;
if (manualOpts) {
@ -166,6 +167,9 @@ export class Page {
this.callbacks = this.callbacks.filter((item) => item.id !== id);
};
}
getPathKey() {
return getPathKey();
}
/**
* basename
* @returns
@ -178,12 +182,26 @@ export class Page {
getAppPath() {
return this.path;
}
/**
* key
* @returns
*/
getAppKey() {
return this.key;
}
/**
*
* @param path
* @returns
*/
decodePath(path: string) {
return decodeURIComponent(path);
}
/**
*
* @param path
* @returns
*/
encodePath(path: string) {
return encodeURIComponent(path);
}
@ -214,6 +232,12 @@ export class Page {
this.popstate({ state } as any, { type: 'all' });
}
}
/**
*
* @param path
* @param state
* @param check
*/
replace(path: string, state?: any, check?: boolean) {
let _check = check ?? true;
window.history.replaceState(state, '', this.basename + path);
@ -221,6 +245,9 @@ export class Page {
this.popstate({ state } as any, { type: 'all' });
}
}
/**
*
*/
refresh() {
const state = window.history.state;
this.popstate({ state } as any, { type: 'all' });