-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tanstack query and router #14
Merged
chescalante
merged 5 commits into
chescalante:main
from
martinc1991:feature/add-tanstack-query-and-router
Jul 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b1c2647
Add @tanstack/react-query
martinc1991 90c84d4
Add @tanstack/react-router
martinc1991 ca8570e
Merge branch 'main' into feature/add-tanstack-query-and-router
martinc1991 739b93e
Add @tanstack/react-router 2
martinc1991 85b732b
Put layout on _root layout
martinc1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,8 @@ | ||
import reactLogo from "@/assets/react.svg"; | ||
import { Button } from "@/components"; | ||
import { useState } from "react"; | ||
import "./App.css"; | ||
import viteLogo from "/vite.svg"; | ||
import { router } from "@/shared/config/tanstackRouter"; | ||
import { RouterProvider } from "@tanstack/react-router"; | ||
|
||
function App() { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-col items-center"> | ||
<a href="https://vitejs.dev" target="_blank" rel="noreferrer"> | ||
<img src={viteLogo} className="logo" alt="Vite logo" /> | ||
</a> | ||
<a href="https://react.dev" target="_blank" rel="noreferrer"> | ||
<img src={reactLogo} className="logo react" alt="React logo" /> | ||
</a> | ||
</div> | ||
<h1>Vite + React</h1> | ||
<div className="card"> | ||
<Button onClick={() => setCount((count) => count + 1)}>count is {count}</Button> | ||
<p> | ||
Edit <code>src/App.tsx</code> and save to test HMR | ||
</p> | ||
</div> | ||
<p className="read-the-docs">Click on the Vite and React logos to learn more</p> | ||
</> | ||
); | ||
return <RouterProvider router={router} />; | ||
} | ||
|
||
export default App; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Link } from "@tanstack/react-router"; | ||
|
||
export default function Layout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<div className="w-screen h-screen"> | ||
<div className="p-2 flex gap-2"> | ||
<Link to="/" className="[&.active]:font-bold"> | ||
Home | ||
</Link>{" "} | ||
<Link to="/about" className="[&.active]:font-bold"> | ||
About | ||
</Link> | ||
</div> | ||
<hr /> | ||
<main className="p-2">{children}</main> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* prettier-ignore-start */ | ||
|
||
/* eslint-disable */ | ||
|
||
// @ts-nocheck | ||
|
||
// noinspection JSUnusedGlobalSymbols | ||
|
||
// This file is auto-generated by TanStack Router | ||
|
||
import { createFileRoute } from '@tanstack/react-router' | ||
|
||
// Import Routes | ||
|
||
import { Route as rootRoute } from './routes/__root' | ||
|
||
// Create Virtual Routes | ||
|
||
const AboutLazyImport = createFileRoute('/about')() | ||
const IndexLazyImport = createFileRoute('/')() | ||
|
||
// Create/Update Routes | ||
|
||
const AboutLazyRoute = AboutLazyImport.update({ | ||
path: '/about', | ||
getParentRoute: () => rootRoute, | ||
} as any).lazy(() => import('./routes/about.lazy').then((d) => d.Route)) | ||
|
||
const IndexLazyRoute = IndexLazyImport.update({ | ||
path: '/', | ||
getParentRoute: () => rootRoute, | ||
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route)) | ||
|
||
// Populate the FileRoutesByPath interface | ||
|
||
declare module '@tanstack/react-router' { | ||
interface FileRoutesByPath { | ||
'/': { | ||
id: '/' | ||
path: '/' | ||
fullPath: '/' | ||
preLoaderRoute: typeof IndexLazyImport | ||
parentRoute: typeof rootRoute | ||
} | ||
'/about': { | ||
id: '/about' | ||
path: '/about' | ||
fullPath: '/about' | ||
preLoaderRoute: typeof AboutLazyImport | ||
parentRoute: typeof rootRoute | ||
} | ||
} | ||
} | ||
|
||
// Create and export the route tree | ||
|
||
export const routeTree = rootRoute.addChildren({ | ||
IndexLazyRoute, | ||
AboutLazyRoute, | ||
}) | ||
|
||
/* prettier-ignore-end */ | ||
|
||
/* ROUTE_MANIFEST_START | ||
{ | ||
"routes": { | ||
"__root__": { | ||
"filePath": "__root.tsx", | ||
"children": [ | ||
"/", | ||
"/about" | ||
] | ||
}, | ||
"/": { | ||
"filePath": "index.lazy.tsx" | ||
}, | ||
"/about": { | ||
"filePath": "about.lazy.tsx" | ||
} | ||
} | ||
} | ||
ROUTE_MANIFEST_END */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createRootRoute, Outlet } from "@tanstack/react-router"; | ||
import React from "react"; | ||
|
||
const TanStackRouterDevtools = | ||
process.env.NODE_ENV === "production" | ||
? () => null // Render nothing in production | ||
: React.lazy(() => | ||
import("@tanstack/router-devtools").then((res) => ({ | ||
default: res.TanStackRouterDevtools, | ||
})) | ||
); | ||
|
||
export const Route = createRootRoute({ | ||
component: () => ( | ||
<> | ||
<Outlet /> | ||
<TanStackRouterDevtools /> | ||
</> | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Layout from "@/layout"; | ||
import { createLazyFileRoute } from "@tanstack/react-router"; | ||
|
||
export const Route = createLazyFileRoute("/about")({ | ||
component: About, | ||
}); | ||
|
||
function About() { | ||
return <Layout>Hello /about!</Layout>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Layout from "@/layout"; | ||
import { createLazyFileRoute } from "@tanstack/react-router"; | ||
|
||
export const Route = createLazyFileRoute("/")({ | ||
component: Index, | ||
}); | ||
|
||
function Index() { | ||
return ( | ||
<Layout> | ||
<h3>Welcome Home!</h3> | ||
</Layout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { routeTree } from "@/routeTree.gen"; | ||
import { createRouter } from "@tanstack/react-router"; | ||
|
||
export const router = createRouter({ routeTree }); | ||
|
||
declare module "@tanstack/react-router" { | ||
interface Register { | ||
router: typeof router; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a way to put a general Layout for all the routes, I think is creating a _layout.tsx in the root of routes folder
https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#pathless--layout-routes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw that, but I made it using what i saw in the demented-games repo. should i do it this way instead?