@ktjs/router 0.14.2 → 0.14.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/dist/index.d.ts +2 -0
- package/dist/index.iife.js +28 -1
- package/dist/index.legacy.js +29 -1
- package/dist/index.mjs +28 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.iife.js
CHANGED
|
@@ -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
|
+
/**
|
|
199
|
+
* Initialize current route from URL
|
|
200
|
+
*/
|
|
201
|
+
const initCurrentRoute = () => {
|
|
202
|
+
const hash = window.location.hash.slice(1); // Remove '#'
|
|
203
|
+
if (!hash) {
|
|
204
|
+
return (current = 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 (current = null);
|
|
213
|
+
}
|
|
214
|
+
// Build route context
|
|
215
|
+
return (current = {
|
|
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
|
+
};
|
|
198
224
|
let current = null;
|
|
199
|
-
const history = [];
|
|
225
|
+
const history = current ? [current] : [];
|
|
200
226
|
// # methods
|
|
201
227
|
const executeGuardsSync = (to, from, guardLevel) => {
|
|
202
228
|
try {
|
|
@@ -484,6 +510,7 @@ var __ktjs_router__ = (function (exports) {
|
|
|
484
510
|
forward() {
|
|
485
511
|
window.history.forward();
|
|
486
512
|
},
|
|
513
|
+
initCurrentRoute,
|
|
487
514
|
};
|
|
488
515
|
};
|
|
489
516
|
|
package/dist/index.legacy.js
CHANGED
|
@@ -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
|
+
/**
|
|
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 (current = 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 (current = null);
|
|
308
|
+
}
|
|
309
|
+
// Build route context
|
|
310
|
+
return (current = {
|
|
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
|
+
};
|
|
292
319
|
var current = null;
|
|
293
|
-
var history = [];
|
|
320
|
+
var history = current ? [current] : [];
|
|
294
321
|
// # methods
|
|
295
322
|
var executeGuardsSync = function (to, from, guardLevel) {
|
|
296
323
|
try {
|
|
@@ -620,6 +647,7 @@ var __ktjs_router__ = (function (exports) {
|
|
|
620
647
|
forward: function () {
|
|
621
648
|
window.history.forward();
|
|
622
649
|
},
|
|
650
|
+
initCurrentRoute: initCurrentRoute,
|
|
623
651
|
};
|
|
624
652
|
};
|
|
625
653
|
|
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
|
+
/**
|
|
196
|
+
* Initialize current route from URL
|
|
197
|
+
*/
|
|
198
|
+
const initCurrentRoute = () => {
|
|
199
|
+
const hash = window.location.hash.slice(1); // Remove '#'
|
|
200
|
+
if (!hash) {
|
|
201
|
+
return (current = 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 (current = null);
|
|
210
|
+
}
|
|
211
|
+
// Build route context
|
|
212
|
+
return (current = {
|
|
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
|
+
};
|
|
195
221
|
let current = null;
|
|
196
|
-
const history = [];
|
|
222
|
+
const history = current ? [current] : [];
|
|
197
223
|
// # methods
|
|
198
224
|
const executeGuardsSync = (to, from, guardLevel) => {
|
|
199
225
|
try {
|
|
@@ -481,6 +507,7 @@ const createRouter = (config) => {
|
|
|
481
507
|
forward() {
|
|
482
508
|
window.history.forward();
|
|
483
509
|
},
|
|
510
|
+
initCurrentRoute,
|
|
484
511
|
};
|
|
485
512
|
};
|
|
486
513
|
|