From 1cd9d5c64d3fb4f1a7100e2d426a5d85c44954cb Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:11:09 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix(frontend):=20=E3=83=87=E3=83=83?= =?UTF-8?q?=E3=82=ADUI=E3=81=A7matchAll=E3=81=AB=E5=85=A5=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=82=89=E6=96=B0=E3=81=97=E3=81=84=E3=82=BF=E3=83=96?= =?UTF-8?q?=E3=81=A7=E9=96=8B=E3=81=8F=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/ui/deck.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/frontend/src/ui/deck.vue b/packages/frontend/src/ui/deck.vue index bdb62dca15..14a08f50ba 100644 --- a/packages/frontend/src/ui/deck.vue +++ b/packages/frontend/src/ui/deck.vue @@ -138,7 +138,12 @@ mainRouter.navHook = (path, flag): boolean => { if (flag === 'forcePage') return false; const noMainColumn = !deckStore.state.columns.some(x => x.type === 'main'); if (deckStore.state.navWindow || noMainColumn) { - os.pageWindow(path); + const res = mainRouter.resolve(path); + if (res?.route.path === '/:(*)') { + window.open(path, '_blank', 'noopener'); + } else { + os.pageWindow(path); + } return true; } return false; From 7e82a5f538a36ba48014acb075818ecbedc3d715 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:59:55 +0900 Subject: [PATCH 2/2] =?UTF-8?q?pageWindow=E3=81=A7=E3=82=82=E6=96=B0?= =?UTF-8?q?=E8=A6=8F=E3=82=BF=E3=83=96=E3=81=A7=E9=96=8B=E3=81=8F=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/components/MkPageWindow.vue | 9 +++++++ packages/frontend/src/nirax.ts | 25 +++++++++++++++---- packages/frontend/src/ui/deck.vue | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/frontend/src/components/MkPageWindow.vue b/packages/frontend/src/components/MkPageWindow.vue index aa4509b14b..7682452999 100644 --- a/packages/frontend/src/components/MkPageWindow.vue +++ b/packages/frontend/src/components/MkPageWindow.vue @@ -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); diff --git a/packages/frontend/src/nirax.ts b/packages/frontend/src/nirax.ts index 6a8ea09ed6..3157185041 100644 --- a/packages/frontend/src/nirax.ts +++ b/packages/frontend/src/nirax.ts @@ -100,7 +100,13 @@ export interface IRouter extends EventEmitter { current: Resolved; currentRef: ShallowRef; currentRoute: ShallowRef; - 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 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 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 { diff --git a/packages/frontend/src/ui/deck.vue b/packages/frontend/src/ui/deck.vue index 14a08f50ba..b6f1b98774 100644 --- a/packages/frontend/src/ui/deck.vue +++ b/packages/frontend/src/ui/deck.vue @@ -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) {