@melodicdev/components 1.6.3 → 1.6.5

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.
@@ -1245,6 +1245,10 @@ var RouteContextEvent = class extends CustomEvent {
1245
1245
  });
1246
1246
  }
1247
1247
  };
1248
+ function resolveRedirectTarget(redirectTo, basePath) {
1249
+ if (redirectTo.startsWith("/")) return redirectTo;
1250
+ return basePath ? `/${basePath}/${redirectTo}` : `/${redirectTo}`;
1251
+ }
1248
1252
  function matchRouteLevel(routes, remainingPath, basePath, accumulatedMatches, accumulatedParams) {
1249
1253
  for (const route of routes) {
1250
1254
  const matcher = new RouteMatcher(route.path);
@@ -1252,21 +1256,31 @@ function matchRouteLevel(routes, remainingPath, basePath, accumulatedMatches, ac
1252
1256
  matches: accumulatedMatches,
1253
1257
  params: accumulatedParams,
1254
1258
  isExactMatch: false,
1255
- redirectTo: route.redirectTo
1259
+ redirectTo: resolveRedirectTarget(route.redirectTo, basePath)
1256
1260
  };
1257
1261
  const exactMatch = matcher.parse(remainingPath);
1258
1262
  if (exactMatch !== null) {
1259
- const fullPath = basePath ? `${basePath}/${route.path}` : route.path;
1263
+ const matchedPath = remainingPath;
1264
+ const fullPath = basePath ? `${basePath}/${matchedPath}` : matchedPath;
1260
1265
  const match = {
1261
1266
  route,
1262
1267
  params: exactMatch,
1263
- matchedPath: route.path,
1268
+ matchedPath,
1264
1269
  remainingPath: "",
1265
1270
  fullPath,
1266
1271
  children: route.children
1267
1272
  };
1268
1273
  Object.assign(accumulatedParams, exactMatch);
1269
1274
  accumulatedMatches.push(match);
1275
+ if (route.children) {
1276
+ const emptyRedirect = route.children.find((child) => child.path === "" && child.redirectTo);
1277
+ if (emptyRedirect && emptyRedirect.redirectTo) return {
1278
+ matches: accumulatedMatches,
1279
+ params: accumulatedParams,
1280
+ isExactMatch: false,
1281
+ redirectTo: resolveRedirectTarget(emptyRedirect.redirectTo, fullPath)
1282
+ };
1283
+ }
1270
1284
  return {
1271
1285
  matches: accumulatedMatches,
1272
1286
  params: accumulatedParams,
@@ -2531,8 +2545,7 @@ var RouterOutletComponent = class RouterOutletComponent$1 {
2531
2545
  const remainingPath = this._context.remainingPath;
2532
2546
  const matchResult = matchRouteTree(this.routes, remainingPath, this._context.basePath);
2533
2547
  if (matchResult.redirectTo) {
2534
- const fullRedirect = this._context.basePath ? `/${this._context.basePath}/${matchResult.redirectTo}`.replace(/\/+/g, "/") : matchResult.redirectTo;
2535
- if (window.location.pathname !== fullRedirect) this._router.navigate(fullRedirect, { replace: true });
2548
+ if (window.location.pathname !== matchResult.redirectTo) this._router.navigate(matchResult.redirectTo, { replace: true });
2536
2549
  return;
2537
2550
  }
2538
2551
  if (matchResult.matches.length > 0) {