-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tanstack-start): Path based routing and Router support (#3932)
Co-authored-by: Joe Bell <[email protected]> Co-authored-by: Stefanos Anagnostou <[email protected]> Co-authored-by: Lennart <[email protected]>
- Loading branch information
1 parent
247b3fd
commit b5c8ade
Showing
58 changed files
with
1,750 additions
and
662 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"@clerk/tanstack-start": minor | ||
--- | ||
|
||
Add support for path based routing and TanStack Router only apps |
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 |
---|---|---|
|
@@ -56,3 +56,6 @@ actions: | |
|
||
integration: | ||
- integration/** | ||
|
||
tanstack: | ||
- packages/tanstack-start/** |
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
Empty file.
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 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 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,33 @@ | ||
import { applicationConfig } from '../models/applicationConfig.js'; | ||
import { templates } from '../templates/index.js'; | ||
|
||
const clerkTanStackLocal = `file:${process.cwd()}/packages/tanstack-start`; | ||
|
||
const router = applicationConfig() | ||
.setName('tanstack-router') | ||
.useTemplate(templates['tanstack-router']) | ||
.setEnvFormatter('public', key => `VITE_${key}`) | ||
// `--install-links` ensures that the @clerk/tanstack-start is installed as a regular dependancie instead of creating symlink | ||
// please do not remove this flag as it's going to break the setup | ||
.addScript('setup', 'npm i --install-links') | ||
.addScript('dev', 'npm run dev') | ||
.addScript('build', 'npm run build') | ||
.addScript('serve', 'npm run start') | ||
.addDependency('@clerk/tanstack-start', clerkTanStackLocal); | ||
|
||
const start = applicationConfig() | ||
.setName('tanstack-start') | ||
.useTemplate(templates['tanstack-start']) | ||
.setEnvFormatter('public', key => `VITE_${key}`) | ||
// `--install-links` ensures that the @clerk/tanstack-start is installed as a regular dependancie instead of creating symlink | ||
// please do not remove this flag as it's going to break the setup | ||
.addScript('setup', 'npm i --install-links') | ||
.addScript('dev', 'npm run dev') | ||
.addScript('build', 'npm run build') | ||
.addScript('serve', 'npm run start') | ||
.addDependency('@clerk/tanstack-start', clerkTanStackLocal); | ||
|
||
export const tanstack = { | ||
start, | ||
router, | ||
} as const; |
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 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 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
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,6 @@ | ||
# Example | ||
|
||
To run this example: | ||
|
||
- `npm install` or `yarn` | ||
- `npm start` or `yarn start` |
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,30 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0" | ||
/> | ||
<title>Vite App</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<style type="text/tailwindcss"> | ||
html { | ||
color-scheme: light dark; | ||
} | ||
* { | ||
@apply border-gray-200 dark:border-gray-800; | ||
} | ||
body { | ||
@apply bg-gray-50 text-gray-950 dark:bg-gray-900 dark:text-gray-200; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script | ||
type="module" | ||
src="/src/main.tsx" | ||
></script> | ||
</body> | ||
</html> |
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,24 @@ | ||
{ | ||
"name": "tanstack-router-react-example-basic-file-based", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite --port=$PORT", | ||
"build": "vite build", | ||
"serve": "vite preview --port=$PORT", | ||
"start": "vite" | ||
}, | ||
"dependencies": { | ||
"@tanstack/react-router": "^1.47.1", | ||
"@tanstack/router-devtools": "^1.47.1", | ||
"@tanstack/router-plugin": "^1.47.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.47", | ||
"@types/react-dom": "^18.2.18", | ||
"@vitejs/plugin-react": "^4.3.1", | ||
"vite": "^5.3.5" | ||
} | ||
} |
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,25 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { RouterProvider, createRouter } from '@tanstack/react-router'; | ||
import { routeTree } from './routeTree.gen'; | ||
|
||
// Set up a Router instance | ||
const router = createRouter({ | ||
routeTree, | ||
defaultPreload: 'intent', | ||
defaultStaleTime: 5000, | ||
}); | ||
|
||
// Register things for typesafety | ||
declare module '@tanstack/react-router' { | ||
interface Register { | ||
router: typeof router; | ||
} | ||
} | ||
|
||
const rootElement = document.getElementById('app')!; | ||
|
||
if (!rootElement.innerHTML) { | ||
const root = ReactDOM.createRoot(rootElement); | ||
root.render(<RouterProvider router={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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { notFound } from '@tanstack/react-router'; | ||
import axios from 'redaxios'; | ||
|
||
export type PostType = { | ||
id: string; | ||
title: string; | ||
body: string; | ||
}; | ||
|
||
export const fetchPost = async (postId: string) => { | ||
console.info(`Fetching post with id ${postId}...`); | ||
await new Promise(r => setTimeout(r, 500)); | ||
const post = await axios | ||
.get<PostType>(`https://jsonplaceholder.typicode.com/posts/${postId}`) | ||
.then(r => r.data) | ||
.catch(err => { | ||
if (err.status === 404) { | ||
throw notFound(); | ||
} | ||
throw err; | ||
}); | ||
|
||
return post; | ||
}; | ||
|
||
export const fetchPosts = async () => { | ||
console.info('Fetching posts...'); | ||
await new Promise(r => setTimeout(r, 500)); | ||
return axios.get<Array<PostType>>('https://jsonplaceholder.typicode.com/posts').then(r => r.data.slice(0, 10)); | ||
}; |
Oops, something went wrong.