Skip to content

Commit

Permalink
Fix root path and update suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Dec 19, 2024
1 parent 79ca69f commit 0dad3fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
11 changes: 8 additions & 3 deletions web/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { createRootRoute, Outlet } from '@tanstack/react-router';
import { createRootRouteWithContext, Outlet } from '@tanstack/react-router';
import { ReactNode } from 'react';

import { Navbar } from '@/components/Navbar';
import { Toaster } from '@/components/ui/Toaster';

export const Route = createRootRoute({
export interface MyRouterContext {
title: string;
suffix?: ReactNode;
}

export const Route = createRootRouteWithContext<MyRouterContext>()({
component: () => (
<>
<Navbar />
<Toaster />
<Outlet />
{/* <TanStackRouterDevtools /> */}
</>
),
});
8 changes: 2 additions & 6 deletions web/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createFileRoute, createRootRouteWithContext, Link } from '@tanstack/react-router';
import { createFileRoute, Link } from '@tanstack/react-router';
import { FiArrowRight } from 'react-icons/fi';

import { useInstanceStatistics } from '@/api/instance_settings';
Expand Down Expand Up @@ -48,10 +48,6 @@ const Page = () => {
);
};

export interface MyRouterContext {
title: string;
}

export const Route = createRootRouteWithContext<MyRouterContext>()({
export const Route = createFileRoute('/')({
component: Page,
});
14 changes: 7 additions & 7 deletions web/src/routes/settings/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
createFileRoute,
Outlet,
useRouteContext,
useRouterState,
} from '@tanstack/react-router';

Expand All @@ -15,13 +14,14 @@ export const Route = createFileRoute('/settings/_layout')({
function RouteComponent() {
const matches = useRouterState({ select: (s) => s.matches });

// @ts-expect-error
// eslint-disable-next-line prefer-destructuring
const title = matches[matches.length - 1].context['title'];
const { title, suffix } = matches[matches.length - 1].context;

return (
<SidePage title={title} sidebar={<SettingsNav />}>
<Outlet />
</SidePage>
<SidePage
title={title}
suffix={suffix}
sidebar={<SettingsNav />}
children={<Outlet />}
/>
);
}
1 change: 1 addition & 0 deletions web/src/routes/settings/_layout/fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export const Route = createFileRoute('/settings/_layout/fields/')({
context() {
return {
title: 'Field Definitions',
suffix: <div>TODO: Create</div>,
};
},
component: RouteComponent,
Expand Down

0 comments on commit 0dad3fd

Please sign in to comment.