/** * @typedef {{ * routeId: string, * path: string, * paramsSchema: string | null, * searchSchema: string | null, * access: "public" | "session-required" | "integration-defined", * loadingSurface: string, * errorSurface: string, * chunkId: string, * title: string, * navigationLabel: string | null, * navigationOrder: number | null * }} RouteDefinition */ /** @param {RouteDefinition} definition */ const route = (definition) => Object.freeze(definition); export const ROUTE_REGISTRY = Object.freeze({ APP_HOME: route({ routeId: "APP_HOME", path: "/", paramsSchema: null, searchSchema: null, access: "public", loadingSurface: "app-shell", errorSurface: "route-boundary", chunkId: "route-home", title: "시작", navigationLabel: "시작", navigationOrder: 10, }), EXAMPLES_UI: route({ routeId: "EXAMPLES_UI", path: "/examples/ui", paramsSchema: null, searchSchema: null, access: "public", loadingSurface: "example-page", errorSurface: "route-boundary", chunkId: "route-examples-ui", title: "UI 구성요소", navigationLabel: "UI 구성요소", navigationOrder: 20, }), EXAMPLES_STATES: route({ routeId: "EXAMPLES_STATES", path: "/examples/states", paramsSchema: null, searchSchema: null, access: "public", loadingSurface: "example-page", errorSurface: "route-boundary", chunkId: "route-examples-states", title: "화면 상태", navigationLabel: "화면 상태", navigationOrder: 30, }), EXAMPLES_AUTH: route({ routeId: "EXAMPLES_AUTH", path: "/examples/auth", paramsSchema: null, searchSchema: null, access: "public", loadingSurface: "example-page", errorSurface: "route-boundary", chunkId: "route-examples-auth", title: "인증 연동", navigationLabel: "인증 연동", navigationOrder: 40, }), SAMPLE_RESOURCE_LIST: route({ routeId: "SAMPLE_RESOURCE_LIST", path: "/sample/resources", paramsSchema: null, searchSchema: "SampleResourceListQuery", access: "integration-defined", loadingSurface: "sample-resource-list", errorSurface: "feature-boundary", chunkId: "route-sample-resources", title: "보호된 연동 지점", navigationLabel: "보호된 연동 지점", navigationOrder: 50, }), NOT_FOUND: route({ routeId: "NOT_FOUND", path: "*", paramsSchema: null, searchSchema: null, access: "public", loadingSurface: "none", errorSurface: "not-found", chunkId: "route-not-found", title: "페이지를 찾을 수 없음", navigationLabel: null, navigationOrder: null, }), }); export const NAVIGATION_ROUTES = Object.freeze( Object.values(ROUTE_REGISTRY) .filter((definition) => definition.navigationOrder !== null) .sort( (left, right) => /** @type {number} */ (left.navigationOrder) - /** @type {number} */ (right.navigationOrder), ), ); /** @param {string} routeId */ export function getRoute(routeId) { const registry = /** @type {Record>} */ ( ROUTE_REGISTRY ); const selected = registry[routeId]; if (!selected) throw new Error(`Unregistered route: ${routeId}`); return selected; } /** @param {string} routeId */ export function routePath(routeId) { return getRoute(routeId).path; }