mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 23:37:15 +08:00
refactor!: next generation AFFiNE code structure (#1176)
This commit is contained in:
42
apps/web/src/hooks/use-router-helper.ts
Normal file
42
apps/web/src/hooks/use-router-helper.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { NextRouter } from 'next/router';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { WorkspaceSubPath } from '../shared';
|
||||
|
||||
export const enum RouteLogic {
|
||||
REPLACE = 'replace',
|
||||
PUSH = 'push',
|
||||
}
|
||||
|
||||
export function useRouterHelper(router: NextRouter) {
|
||||
return useMemo(
|
||||
() => ({
|
||||
jumpToPage: (
|
||||
workspaceId: string,
|
||||
pageId: string,
|
||||
logic: RouteLogic = RouteLogic.PUSH
|
||||
) => {
|
||||
return router[logic]({
|
||||
pathname: `/workspace/[workspaceId]/[pageId]`,
|
||||
query: {
|
||||
workspaceId,
|
||||
pageId,
|
||||
},
|
||||
});
|
||||
},
|
||||
jumpToSubPath: (
|
||||
workspaceId: string,
|
||||
subPath: WorkspaceSubPath,
|
||||
logic: RouteLogic = RouteLogic.PUSH
|
||||
): Promise<boolean> => {
|
||||
return router[logic]({
|
||||
pathname: `/workspace/[workspaceId]/${subPath}`,
|
||||
query: {
|
||||
workspaceId,
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
[router]
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user