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