@ktjs/router 0.14.2 → 0.14.3

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.
@@ -195,8 +195,34 @@ var __ktjs_router__ = (function (exports) {
195
195
  // Normalize routes with default guards
196
196
  normalize(config.routes, '/');
197
197
  const { findByName, match } = createMatcher(routes);
198
- let current = null;
199
- const history = [];
198
+ /**
199
+ * Initialize current route from URL
200
+ */
201
+ const initCurrentRoute = () => {
202
+ const hash = window.location.hash.slice(1); // Remove '#'
203
+ if (!hash) {
204
+ return null;
205
+ }
206
+ // Parse path and query
207
+ const [path, queryString] = hash.split('?');
208
+ const normalizedPath = normalizePath(path);
209
+ // Match route
210
+ const matched = match(normalizedPath);
211
+ if (!matched) {
212
+ return null;
213
+ }
214
+ // Build route context
215
+ return {
216
+ path: normalizedPath,
217
+ name: matched.route.name,
218
+ params: matched.params,
219
+ query: queryString ? parseQuery(queryString) : {},
220
+ meta: matched.route.meta ?? {},
221
+ matched: matched.result,
222
+ };
223
+ };
224
+ let current = initCurrentRoute();
225
+ const history = current ? [current] : [];
200
226
  // # methods
201
227
  const executeGuardsSync = (to, from, guardLevel) => {
202
228
  try {
@@ -289,8 +289,35 @@ var __ktjs_router__ = (function (exports) {
289
289
  // Normalize routes with default guards
290
290
  normalize(config.routes, '/');
291
291
  var _g = createMatcher(routes), findByName = _g.findByName, match = _g.match;
292
- var current = null;
293
- var history = [];
292
+ /**
293
+ * Initialize current route from URL
294
+ */
295
+ var initCurrentRoute = function () {
296
+ var _a;
297
+ var hash = window.location.hash.slice(1); // Remove '#'
298
+ if (!hash) {
299
+ return null;
300
+ }
301
+ // Parse path and query
302
+ var _b = hash.split('?'), path = _b[0], queryString = _b[1];
303
+ var normalizedPath = normalizePath(path);
304
+ // Match route
305
+ var matched = match(normalizedPath);
306
+ if (!matched) {
307
+ return null;
308
+ }
309
+ // Build route context
310
+ return {
311
+ path: normalizedPath,
312
+ name: matched.route.name,
313
+ params: matched.params,
314
+ query: queryString ? parseQuery(queryString) : {},
315
+ meta: (_a = matched.route.meta) !== null && _a !== void 0 ? _a : {},
316
+ matched: matched.result,
317
+ };
318
+ };
319
+ var current = initCurrentRoute();
320
+ var history = current ? [current] : [];
294
321
  // # methods
295
322
  var executeGuardsSync = function (to, from, guardLevel) {
296
323
  try {
package/dist/index.mjs CHANGED
@@ -192,8 +192,34 @@ const createRouter = (config) => {
192
192
  // Normalize routes with default guards
193
193
  normalize(config.routes, '/');
194
194
  const { findByName, match } = createMatcher(routes);
195
- let current = null;
196
- const history = [];
195
+ /**
196
+ * Initialize current route from URL
197
+ */
198
+ const initCurrentRoute = () => {
199
+ const hash = window.location.hash.slice(1); // Remove '#'
200
+ if (!hash) {
201
+ return null;
202
+ }
203
+ // Parse path and query
204
+ const [path, queryString] = hash.split('?');
205
+ const normalizedPath = normalizePath(path);
206
+ // Match route
207
+ const matched = match(normalizedPath);
208
+ if (!matched) {
209
+ return null;
210
+ }
211
+ // Build route context
212
+ return {
213
+ path: normalizedPath,
214
+ name: matched.route.name,
215
+ params: matched.params,
216
+ query: queryString ? parseQuery(queryString) : {},
217
+ meta: matched.route.meta ?? {},
218
+ matched: matched.result,
219
+ };
220
+ };
221
+ let current = initCurrentRoute();
222
+ const history = current ? [current] : [];
197
223
  // # methods
198
224
  const executeGuardsSync = (to, from, guardLevel) => {
199
225
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/router",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "description": "Router for kt.js - client-side routing with navigation guards",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",