@zenithbuild/router 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/runtime.ts +19 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/runtime.ts
CHANGED
|
@@ -140,6 +140,25 @@ export async function navigate(to: string, options: NavigateOptions = {}): Promi
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export function getRoute(): RouteState { return { ...currentRoute } }
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* zenRoute() - Zenith Law: Environment Resolution
|
|
146
|
+
*
|
|
147
|
+
* Canonical primitive for resolving the current route environment.
|
|
148
|
+
* Must be resolved once and execute before state initialization.
|
|
149
|
+
*/
|
|
150
|
+
export function zenRoute(): { path: string; slugs: string[] } {
|
|
151
|
+
const path = typeof window !== 'undefined' ? window.location.pathname : currentRoute.path;
|
|
152
|
+
return {
|
|
153
|
+
path,
|
|
154
|
+
slugs: getSlugs(path)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function getSlugs(path: string): string[] {
|
|
159
|
+
return path.split('/').filter(Boolean);
|
|
160
|
+
}
|
|
161
|
+
|
|
143
162
|
export function onRouteChange(listener: RouteListener): () => void {
|
|
144
163
|
routeListeners.add(listener)
|
|
145
164
|
return () => { routeListeners.delete(listener) }
|