Skip to content

Commit a6124fb

Browse files
committed
Fix redirect guard routing behaviour
1 parent fa154ec commit a6124fb

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@tailor-platform/app-shell": patch
3+
---
4+
5+
Fixed `redirectTo()` guard not working on modules/resources without a component. Index routes are now created for loader-only routes, enabling redirect guards to execute properly.
6+
7+
Fixed sidebar navigation hiding modules/resources that use `redirectTo()` guards. Navigation filtering now only excludes `hidden()` guards, so redirect-guarded items remain visible in the sidebar.

packages/core/src/routing/navigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const buildNavItems = async (props: BuildNavItemsProps) => {
6464
if (module.path.startsWith(":")) return null;
6565

6666
const guardResult = await runGuards(module.guards);
67-
if (guardResult.type !== "pass") return null;
67+
if (guardResult.type === "hidden") return null;
6868

6969
const visibleResources = await filterVisibleResources(
7070
module.resources,
@@ -100,7 +100,7 @@ const filterVisibleResources = async (
100100
if (resource.path.startsWith(":")) return null;
101101

102102
const guardResult = await runGuards(resource.guards);
103-
if (guardResult.type !== "pass") return null;
103+
if (guardResult.type === "hidden") return null;
104104

105105
const resourcePath = `${basePath}/${resource.path}`;
106106
const resourceTitle = resolveTitle(resource.meta.title, resource.path);

packages/core/src/routing/routes.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ const createRoute = (
3939
Component: source.component,
4040
...(source.loader && { loader: source.loader }),
4141
}
42-
: undefined;
42+
: source.loader
43+
? {
44+
index: true,
45+
loader: source.loader,
46+
// Component is required to suppress React Router's warning about empty leaf routes,
47+
// even though the loader always redirects/throws and this component will never render.
48+
Component: () => null,
49+
}
50+
: undefined;
4351

4452
return {
4553
path: source.path,

0 commit comments

Comments
 (0)