Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('index', () => {
'initFull',
'getRouterContext',
'setRouterContext',
'isRouteActive',
];

// Act.
Expand Down
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export type * from "./types.js";
export { location } from "./core/Location.js";
export * from './RouterTrace/RouterTrace.svelte';
export { default as RouterTrace } from './RouterTrace/RouterTrace.svelte';
export * from "./public-utils.js";
18 changes: 18 additions & 0 deletions src/lib/public-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RouterEngine } from "./core/RouterEngine.svelte.js";
import type { RouteStatus } from "./types.js";

/**
* Checks if a specific route is active according to the provided router engine or route status record.
*
* **Note:** `false` is also returned if no router engine is provided or if no route key is specified.
* @param rsOrRouter A router engine or a router engine's route status record.
* @param key The route key to check for activity.
* @returns `true` if the specified route is active; otherwise, `false`.
*/
export function isRouteActive(
rsOrRouter: RouterEngine | Record<string, RouteStatus> | null | undefined,
key: string | null | undefined
): boolean {
const rs = rsOrRouter instanceof RouterEngine ? rsOrRouter.routeStatus : rsOrRouter;
return !!rs?.[key ?? '']?.match;
}