@ktjs/router 0.14.1 → 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.
- package/dist/index.d.ts +4 -2
- package/dist/index.iife.js +30 -3
- package/dist/index.legacy.js +33 -5
- package/dist/index.mjs +30 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ interface RawRouteConfig {
|
|
|
37
37
|
component: () => HTMLElement | Promise<HTMLElement>;
|
|
38
38
|
/** Route-level guard executed before entering this route. Return false to block, string/object to redirect */
|
|
39
39
|
beforeEnter?: (
|
|
40
|
-
context: RouteContext
|
|
40
|
+
context: RouteContext,
|
|
41
41
|
) => string | NavBaseOptions | boolean | void | Promise<string | NavBaseOptions | boolean | void>;
|
|
42
42
|
/** Route-level hook executed after navigation */
|
|
43
43
|
after?: (context: RouteContext) => void | Promise<void>;
|
|
@@ -99,13 +99,15 @@ interface NavOptions extends NavBaseOptions {
|
|
|
99
99
|
* Router configuration
|
|
100
100
|
*/
|
|
101
101
|
interface RouterConfig {
|
|
102
|
+
baseUrl?: string;
|
|
103
|
+
|
|
102
104
|
/** Array of route definitions */
|
|
103
105
|
routes: RawRouteConfig[];
|
|
104
106
|
|
|
105
107
|
/** Global guard executed before each navigation (except silentPush). Return false to block, string/object to redirect */
|
|
106
108
|
beforeEach?: (
|
|
107
109
|
to: RouteContext,
|
|
108
|
-
from: RouteContext | null
|
|
110
|
+
from: RouteContext | null,
|
|
109
111
|
) => string | NavBaseOptions | boolean | void | Promise<string | NavBaseOptions | boolean | void>;
|
|
110
112
|
|
|
111
113
|
/** Global hook executed after each navigation */
|
package/dist/index.iife.js
CHANGED
|
@@ -169,6 +169,7 @@ var __ktjs_router__ = (function (exports) {
|
|
|
169
169
|
const onNotFound = config.onNotFound ?? defaultHook;
|
|
170
170
|
const onError = config.onError ?? defaultHook;
|
|
171
171
|
const asyncGuards = config.asyncGuards ?? true;
|
|
172
|
+
const baseUrl = config.baseUrl ?? '';
|
|
172
173
|
// # private values
|
|
173
174
|
const routes = [];
|
|
174
175
|
let routerView = null;
|
|
@@ -178,7 +179,7 @@ var __ktjs_router__ = (function (exports) {
|
|
|
178
179
|
const normalize = (rawRoutes, parentPath) => rawRoutes.map((route) => {
|
|
179
180
|
const path = normalizePath(parentPath, route.path);
|
|
180
181
|
const normalized = {
|
|
181
|
-
path,
|
|
182
|
+
path: baseUrl + path,
|
|
182
183
|
name: route.name ?? '',
|
|
183
184
|
meta: route.meta ?? {},
|
|
184
185
|
beforeEnter: route.beforeEnter ?? defaultHook,
|
|
@@ -194,8 +195,34 @@ var __ktjs_router__ = (function (exports) {
|
|
|
194
195
|
// Normalize routes with default guards
|
|
195
196
|
normalize(config.routes, '/');
|
|
196
197
|
const { findByName, match } = createMatcher(routes);
|
|
197
|
-
|
|
198
|
-
|
|
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] : [];
|
|
199
226
|
// # methods
|
|
200
227
|
const executeGuardsSync = (to, from, guardLevel) => {
|
|
201
228
|
try {
|
package/dist/index.legacy.js
CHANGED
|
@@ -253,13 +253,14 @@ var __ktjs_router__ = (function (exports) {
|
|
|
253
253
|
* Create a new router instance
|
|
254
254
|
*/
|
|
255
255
|
var createRouter = function (config) {
|
|
256
|
-
var _a, _b, _c, _d, _e;
|
|
256
|
+
var _a, _b, _c, _d, _e, _f;
|
|
257
257
|
// # default configs
|
|
258
258
|
var beforeEach = (_a = config.beforeEach) !== null && _a !== void 0 ? _a : defaultHook;
|
|
259
259
|
var afterEach = (_b = config.afterEach) !== null && _b !== void 0 ? _b : defaultHook;
|
|
260
260
|
var onNotFound = (_c = config.onNotFound) !== null && _c !== void 0 ? _c : defaultHook;
|
|
261
261
|
var onError = (_d = config.onError) !== null && _d !== void 0 ? _d : defaultHook;
|
|
262
262
|
var asyncGuards = (_e = config.asyncGuards) !== null && _e !== void 0 ? _e : true;
|
|
263
|
+
var baseUrl = (_f = config.baseUrl) !== null && _f !== void 0 ? _f : '';
|
|
263
264
|
// # private values
|
|
264
265
|
var routes = [];
|
|
265
266
|
var routerView = null;
|
|
@@ -271,7 +272,7 @@ var __ktjs_router__ = (function (exports) {
|
|
|
271
272
|
var _a, _b, _c, _d;
|
|
272
273
|
var path = normalizePath(parentPath, route.path);
|
|
273
274
|
var normalized = {
|
|
274
|
-
path: path,
|
|
275
|
+
path: baseUrl + path,
|
|
275
276
|
name: (_a = route.name) !== null && _a !== void 0 ? _a : '',
|
|
276
277
|
meta: (_b = route.meta) !== null && _b !== void 0 ? _b : {},
|
|
277
278
|
beforeEnter: (_c = route.beforeEnter) !== null && _c !== void 0 ? _c : defaultHook,
|
|
@@ -287,9 +288,36 @@ var __ktjs_router__ = (function (exports) {
|
|
|
287
288
|
};
|
|
288
289
|
// Normalize routes with default guards
|
|
289
290
|
normalize(config.routes, '/');
|
|
290
|
-
var
|
|
291
|
-
|
|
292
|
-
|
|
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 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] : [];
|
|
293
321
|
// # methods
|
|
294
322
|
var executeGuardsSync = function (to, from, guardLevel) {
|
|
295
323
|
try {
|
package/dist/index.mjs
CHANGED
|
@@ -166,6 +166,7 @@ const createRouter = (config) => {
|
|
|
166
166
|
const onNotFound = config.onNotFound ?? defaultHook;
|
|
167
167
|
const onError = config.onError ?? defaultHook;
|
|
168
168
|
const asyncGuards = config.asyncGuards ?? true;
|
|
169
|
+
const baseUrl = config.baseUrl ?? '';
|
|
169
170
|
// # private values
|
|
170
171
|
const routes = [];
|
|
171
172
|
let routerView = null;
|
|
@@ -175,7 +176,7 @@ const createRouter = (config) => {
|
|
|
175
176
|
const normalize = (rawRoutes, parentPath) => rawRoutes.map((route) => {
|
|
176
177
|
const path = normalizePath(parentPath, route.path);
|
|
177
178
|
const normalized = {
|
|
178
|
-
path,
|
|
179
|
+
path: baseUrl + path,
|
|
179
180
|
name: route.name ?? '',
|
|
180
181
|
meta: route.meta ?? {},
|
|
181
182
|
beforeEnter: route.beforeEnter ?? defaultHook,
|
|
@@ -191,8 +192,34 @@ const createRouter = (config) => {
|
|
|
191
192
|
// Normalize routes with default guards
|
|
192
193
|
normalize(config.routes, '/');
|
|
193
194
|
const { findByName, match } = createMatcher(routes);
|
|
194
|
-
|
|
195
|
-
|
|
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] : [];
|
|
196
223
|
// # methods
|
|
197
224
|
const executeGuardsSync = (to, from, guardLevel) => {
|
|
198
225
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ktjs/router",
|
|
3
|
-
"version": "0.14.
|
|
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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"directory": "packages/router"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ktjs/core": "0.14.
|
|
34
|
+
"@ktjs/core": "0.14.6"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "rollup -c rollup.config.mjs",
|