diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 597c851..5496c20 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -11,19 +11,14 @@ // Import Routes import { Route as rootRoute } from './routes/__root' -import { Route as RecipesImport } from './routes/recipes' import { Route as LoginImport } from './routes/login' import { Route as AuthImport } from './routes/_auth' import { Route as AuthIndexImport } from './routes/_auth/index' -import { Route as RecipesUsernameSlugImport } from './routes/recipes_/$username.$slug' +import { Route as AuthRecipesImport } from './routes/_auth/recipes' +import { Route as AuthRecipesUsernameSlugImport } from './routes/_auth/recipes_/$username.$slug' // Create/Update Routes -const RecipesRoute = RecipesImport.update({ - path: '/recipes', - getParentRoute: () => rootRoute, -} as any) - const LoginRoute = LoginImport.update({ path: '/login', getParentRoute: () => rootRoute, @@ -39,9 +34,14 @@ const AuthIndexRoute = AuthIndexImport.update({ getParentRoute: () => AuthRoute, } as any) -const RecipesUsernameSlugRoute = RecipesUsernameSlugImport.update({ +const AuthRecipesRoute = AuthRecipesImport.update({ + path: '/recipes', + getParentRoute: () => AuthRoute, +} as any) + +const AuthRecipesUsernameSlugRoute = AuthRecipesUsernameSlugImport.update({ path: '/recipes/$username/$slug', - getParentRoute: () => rootRoute, + getParentRoute: () => AuthRoute, } as any) // Populate the FileRoutesByPath interface @@ -62,12 +62,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof LoginImport parentRoute: typeof rootRoute } - '/recipes': { - id: '/recipes' + '/_auth/recipes': { + id: '/_auth/recipes' path: '/recipes' fullPath: '/recipes' - preLoaderRoute: typeof RecipesImport - parentRoute: typeof rootRoute + preLoaderRoute: typeof AuthRecipesImport + parentRoute: typeof AuthImport } '/_auth/': { id: '/_auth/' @@ -76,12 +76,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof AuthIndexImport parentRoute: typeof AuthImport } - '/recipes/$username/$slug': { - id: '/recipes/$username/$slug' + '/_auth/recipes/$username/$slug': { + id: '/_auth/recipes/$username/$slug' path: '/recipes/$username/$slug' fullPath: '/recipes/$username/$slug' - preLoaderRoute: typeof RecipesUsernameSlugImport - parentRoute: typeof rootRoute + preLoaderRoute: typeof AuthRecipesUsernameSlugImport + parentRoute: typeof AuthImport } } } @@ -89,10 +89,12 @@ declare module '@tanstack/react-router' { // Create and export the route tree export const routeTree = rootRoute.addChildren({ - AuthRoute: AuthRoute.addChildren({ AuthIndexRoute }), + AuthRoute: AuthRoute.addChildren({ + AuthRecipesRoute, + AuthIndexRoute, + AuthRecipesUsernameSlugRoute, + }), LoginRoute, - RecipesRoute, - RecipesUsernameSlugRoute, }) /* prettier-ignore-end */ @@ -104,29 +106,31 @@ export const routeTree = rootRoute.addChildren({ "filePath": "__root.tsx", "children": [ "/_auth", - "/login", - "/recipes", - "/recipes/$username/$slug" + "/login" ] }, "/_auth": { "filePath": "_auth.tsx", "children": [ - "/_auth/" + "/_auth/recipes", + "/_auth/", + "/_auth/recipes/$username/$slug" ] }, "/login": { "filePath": "login.tsx" }, - "/recipes": { - "filePath": "recipes.tsx" + "/_auth/recipes": { + "filePath": "_auth/recipes.tsx", + "parent": "/_auth" }, "/_auth/": { "filePath": "_auth/index.tsx", "parent": "/_auth" }, - "/recipes/$username/$slug": { - "filePath": "recipes_/$username.$slug.tsx" + "/_auth/recipes/$username/$slug": { + "filePath": "_auth/recipes_/$username.$slug.tsx", + "parent": "/_auth" } } } diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 59ef13d..9da6112 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -22,11 +22,18 @@ const RootLayout = () => { return ( <> -
-

Hello, World.

- +
+

Meals Made Easy

+ +
+
-
+ + ) diff --git a/src/routes/_auth/index.tsx b/src/routes/_auth/index.tsx index 74b996d..ac927c8 100644 --- a/src/routes/_auth/index.tsx +++ b/src/routes/_auth/index.tsx @@ -1,19 +1,7 @@ -import { useQuery } from '@tanstack/react-query' -import { createFileRoute } from '@tanstack/react-router' +import { createFileRoute, redirect } from '@tanstack/react-router' export const Route = createFileRoute('/_auth/')({ - component: () => { - const client = useQuery({ - queryKey: ['index'], - queryFn() { - return 'Hello, Jesse!' - } - }) - return ( -
-

Index Page – You are logged in.

- {client.data ?

{client.data}

: null} -
- ) + beforeLoad() { + throw redirect({ to: '/recipes' }) } }) diff --git a/src/routes/_auth/recipes.tsx b/src/routes/_auth/recipes.tsx new file mode 100644 index 0000000..2f058e8 --- /dev/null +++ b/src/routes/_auth/recipes.tsx @@ -0,0 +1,6 @@ +import { createFileRoute } from '@tanstack/react-router' +import Recipes from '../../pages/recipes/Recipes' + +export const Route = createFileRoute('/_auth/recipes')({ + component: Recipes +}) diff --git a/src/routes/recipes_/$username.$slug.tsx b/src/routes/_auth/recipes_/$username.$slug.tsx similarity index 78% rename from src/routes/recipes_/$username.$slug.tsx rename to src/routes/_auth/recipes_/$username.$slug.tsx index b87c474..47f9913 100644 --- a/src/routes/recipes_/$username.$slug.tsx +++ b/src/routes/_auth/recipes_/$username.$slug.tsx @@ -4,11 +4,11 @@ import { useLoaderData, useParams } from '@tanstack/react-router' -import { ApiError } from '../../api/ApiError' -import getRecipe from '../../api/getRecipe' -import Recipe from '../../pages/recipe/Recipe' +import { ApiError } from '../../../api/ApiError' +import getRecipe from '../../../api/getRecipe' +import Recipe from '../../../pages/recipe/Recipe' -export const Route = createFileRoute('/recipes/$username/$slug')({ +export const Route = createFileRoute('/_auth/recipes/$username/$slug')({ loader: ({ abortController, context, params }) => context.queryClient.ensureQueryData({ queryKey: ['recipe', params.username, params.slug], @@ -22,7 +22,7 @@ export const Route = createFileRoute('/recipes/$username/$slug')({ }), component() { const recipe = useLoaderData({ - from: '/recipes/$username/$slug' + from: '/_auth/recipes/$username/$slug' }) return }, @@ -38,7 +38,7 @@ export const Route = createFileRoute('/recipes/$username/$slug')({ }, notFoundComponent() { const { username, slug } = useParams({ - from: '/recipes/$username/$slug' + from: '/_auth/recipes/$username/$slug' }) return (

diff --git a/src/routes/login.tsx b/src/routes/login.tsx index 66ed74d..35f7dcd 100644 --- a/src/routes/login.tsx +++ b/src/routes/login.tsx @@ -27,7 +27,7 @@ const Login = () => { if (loginResult._tag === 'success') { auth.putToken(loginResult.loginView.accessToken, async () => { await router.invalidate() - await navigate({ to: search.redirect ?? '/' }) + await navigate({ to: search.redirect ?? '/recipes' }) }) } else { setError(loginResult.error) @@ -58,7 +58,7 @@ export const Route = createFileRoute('/login')({ }), beforeLoad({ context, search }) { if (context.auth.token) { - throw redirect({ to: search.redirect || '/' }) + throw redirect({ to: search.redirect || '/recipes' }) } }, component: Login diff --git a/src/routes/recipes.tsx b/src/routes/recipes.tsx deleted file mode 100644 index 59f9c47..0000000 --- a/src/routes/recipes.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import { createFileRoute } from '@tanstack/react-router' -import Recipes from '../pages/recipes/Recipes' - -export const Route = createFileRoute('/recipes')({ - component: Recipes -})