File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ describe('index', () => {
1717 'initFull' ,
1818 'getRouterContext' ,
1919 'setRouterContext' ,
20+ 'isRouteActive' ,
2021 ] ;
2122
2223 // Act.
Original file line number Diff line number Diff line change @@ -12,3 +12,4 @@ export type * from "./types.js";
1212export { location } from "./core/Location.js" ;
1313export * from './RouterTrace/RouterTrace.svelte' ;
1414export { default as RouterTrace } from './RouterTrace/RouterTrace.svelte' ;
15+ export * from "./public-utils.js" ;
Original file line number Diff line number Diff line change 1+ import { RouterEngine } from "./core/RouterEngine.svelte.js" ;
2+ import type { RouteStatus } from "./types.js" ;
3+
4+ /**
5+ * Checks if a specific route is active according to the provided router engine or route status record.
6+ *
7+ * **Note:** `false` is also returned if no router engine is provided or if no route key is specified.
8+ * @param rsOrRouter A router engine or a router engine's route status record.
9+ * @param key The route key to check for activity.
10+ * @returns `true` if the specified route is active; otherwise, `false`.
11+ */
12+ export function isRouteActive (
13+ rsOrRouter : RouterEngine | Record < string , RouteStatus > | null | undefined ,
14+ key : string | null | undefined
15+ ) : boolean {
16+ const rs = rsOrRouter instanceof RouterEngine ? rsOrRouter . routeStatus : rsOrRouter ;
17+ return ! ! rs ?. [ key ?? '' ] ?. match ;
18+ }
You can’t perform that action at this time.
0 commit comments