Merge 5249a17c60
into 752606fe88
This commit is contained in:
commit
774b4624b3
|
@ -98,6 +98,15 @@ windowRouter.addListener('replace', ctx => {
|
||||||
history.value.push({ path: ctx.path, key: ctx.key });
|
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();
|
windowRouter.init();
|
||||||
|
|
||||||
provide('router', windowRouter);
|
provide('router', windowRouter);
|
||||||
|
|
|
@ -109,7 +109,13 @@ export interface IRouter extends EventEmitter<RouterEvent> {
|
||||||
current: Resolved;
|
current: Resolved;
|
||||||
currentRef: ShallowRef<Resolved>;
|
currentRef: ShallowRef<Resolved>;
|
||||||
currentRoute: ShallowRef<RouteDef>;
|
currentRoute: ShallowRef<RouteDef>;
|
||||||
navHook: ((path: string, flag?: RouterFlag) => boolean) | null;
|
|
||||||
|
/**
|
||||||
|
* ナビゲーションフック
|
||||||
|
*
|
||||||
|
* `true`でナビゲーションをキャンセル、`false`またはResolvedオブジェクトでナビゲーションを続行
|
||||||
|
*/
|
||||||
|
navHook: ((path: string, flag?: RouterFlag) => boolean | Resolved) | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ルートの初期化(eventListenerの定義後に必ず呼び出すこと)
|
* ルートの初期化(eventListenerの定義後に必ず呼び出すこと)
|
||||||
|
@ -199,7 +205,7 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
|
||||||
private currentKey = Date.now().toString();
|
private currentKey = Date.now().toString();
|
||||||
private redirectCount = 0;
|
private redirectCount = 0;
|
||||||
|
|
||||||
public navHook: ((path: string, flag?: RouterFlag) => boolean) | null = null;
|
public navHook: ((path: string, flag?: RouterFlag) => boolean | Resolved) | null = null;
|
||||||
|
|
||||||
constructor(routes: Router['routes'], currentPath: Router['currentPath'], isLoggedIn: boolean, notFoundPageComponent: Component) {
|
constructor(routes: Router['routes'], currentPath: Router['currentPath'], isLoggedIn: boolean, notFoundPageComponent: Component) {
|
||||||
super();
|
super();
|
||||||
|
@ -412,11 +418,20 @@ export class Router extends EventEmitter<RouterEvent> implements IRouter {
|
||||||
this.emit('same');
|
this.emit('same');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let res: Resolved | null = null;
|
||||||
if (this.navHook) {
|
if (this.navHook) {
|
||||||
const cancel = this.navHook(path, flag);
|
const hookRes = this.navHook(path, flag);
|
||||||
if (cancel) return;
|
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 === '/:(*)') {
|
if (res.route.path === '/:(*)') {
|
||||||
location.href = path;
|
location.href = path;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -135,11 +135,16 @@ const columnComponents = {
|
||||||
roleTimeline: XRoleTimelineColumn,
|
roleTimeline: XRoleTimelineColumn,
|
||||||
};
|
};
|
||||||
|
|
||||||
mainRouter.navHook = (path, flag): boolean => {
|
mainRouter.navHook = (path, flag) => {
|
||||||
if (flag === 'forcePage') return false;
|
if (flag === 'forcePage') return false;
|
||||||
const noMainColumn = !deckStore.state.columns.some(x => x.type === 'main');
|
const noMainColumn = !deckStore.state.columns.some(x => x.type === 'main');
|
||||||
if (deckStore.state.navWindow || noMainColumn) {
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue