pageWindowでも新規タブで開くように

This commit is contained in:
kakkokari-gtyih 2024-04-30 12:59:55 +09:00
parent 1cd9d5c64d
commit 7e82a5f538
3 changed files with 30 additions and 6 deletions

View File

@ -98,6 +98,15 @@ windowRouter.addListener('replace', ctx => {
history.value.push({ path: ctx.path, key: ctx.key });
});
windowRouter.navHook = (path) => {
const res = windowRouter.resolve(path);
if (res?.route.path === '/:(*)') {
window.open(path, '_blank', 'noopener');
return true;
}
return res ?? false;
};
windowRouter.init();
provide('router', windowRouter);

View File

@ -100,7 +100,13 @@ export interface IRouter extends EventEmitter<RouterEvent> {
current: Resolved;
currentRef: ShallowRef<Resolved>;
currentRoute: ShallowRef<RouteDef>;
navHook: ((path: string, flag?: any) => boolean) | null;
/**
*
*
* `true``false`Resolvedオブジェクトでナビゲーションを続行
*/
navHook: ((path: string, flag?: any) => boolean | Resolved) | null;
/**
* eventListenerの定義後に必ず呼び出すこと
@ -190,7 +196,7 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
private currentKey = Date.now().toString();
private redirectCount = 0;
public navHook: ((path: string, flag?: any) => boolean) | null = null;
public navHook: ((path: string, flag?: any) => boolean | Resolved) | null = null;
constructor(routes: Router['routes'], currentPath: Router['currentPath'], isLoggedIn: boolean, notFoundPageComponent: Component) {
super();
@ -403,11 +409,20 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
this.emit('same');
return;
}
let res: Resolved | null = null;
if (this.navHook) {
const cancel = this.navHook(path, flag);
if (cancel) return;
const hookRes = this.navHook(path, flag);
if (hookRes === true) return;
if (hookRes !== false) {
res = hookRes;
}
const res = this.navigate(path, null);
}
if (res == null) {
res = this.navigate(path, null);
}
if (res.route.path === '/:(*)') {
location.href = path;
} else {

View File

@ -134,7 +134,7 @@ const columnComponents = {
roleTimeline: XRoleTimelineColumn,
};
mainRouter.navHook = (path, flag): boolean => {
mainRouter.navHook = (path, flag) => {
if (flag === 'forcePage') return false;
const noMainColumn = !deckStore.state.columns.some(x => x.type === 'main');
if (deckStore.state.navWindow || noMainColumn) {