mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-25 00:49:17 +09:00
enhance(client): improve usability
This commit is contained in:
parent
7dd9f93efb
commit
62f8af4891
@ -61,6 +61,7 @@ export class Router extends EventEmitter<{
|
|||||||
props: Map<string, string> | null;
|
props: Map<string, string> | null;
|
||||||
key: string;
|
key: string;
|
||||||
}) => void;
|
}) => void;
|
||||||
|
same: () => void;
|
||||||
}> {
|
}> {
|
||||||
private routes: RouteDef[];
|
private routes: RouteDef[];
|
||||||
private currentPath: string;
|
private currentPath: string;
|
||||||
@ -210,11 +211,15 @@ export class Router extends EventEmitter<{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public push(path: string) {
|
public push(path: string) {
|
||||||
|
const beforePath = this.currentPath;
|
||||||
|
if (path === beforePath) {
|
||||||
|
this.emit('same');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.navHook) {
|
if (this.navHook) {
|
||||||
const cancel = this.navHook(path);
|
const cancel = this.navHook(path);
|
||||||
if (cancel) return;
|
if (cancel) return;
|
||||||
}
|
}
|
||||||
const beforePath = this.currentPath;
|
|
||||||
this.navigate(path, null);
|
this.navigate(path, null);
|
||||||
this.emit('push', {
|
this.emit('push', {
|
||||||
beforePath,
|
beforePath,
|
||||||
|
@ -258,6 +258,10 @@ mainRouter.addListener('push', ctx => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mainRouter.addListener('same', () => {
|
||||||
|
window.scroll({ top: 0, behavior: 'smooth' });
|
||||||
|
});
|
||||||
|
|
||||||
window.addEventListener('popstate', (event) => {
|
window.addEventListener('popstate', (event) => {
|
||||||
mainRouter.change(location.pathname + location.search + location.hash, event.state?.key);
|
mainRouter.change(location.pathname + location.search + location.hash, event.state?.key);
|
||||||
const scrollPos = scrollPosStore.get(event.state?.key) ?? 0;
|
const scrollPos = scrollPosStore.get(event.state?.key) ?? 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user