Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/router/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@
"label": "Kitchen Sink + Solid Query (code-based)",
"to": "framework/solid/examples/kitchen-sink-solid-query"
},
{
"label": "Location Masking",
"to": "framework/react/examples/location-masking"
},
{
"label": "Authenticated Routes",
"to": "framework/solid/examples/authenticated-routes"
Expand Down
38 changes: 23 additions & 15 deletions examples/react/location-masking/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
useRouterState,
} from '@tanstack/react-router'
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
import axios from 'redaxios'
import * as Dialog from '@radix-ui/react-dialog'
import type { ErrorComponentProps } from '@tanstack/react-router'
import './styles.css'
Expand All @@ -31,25 +30,34 @@ class NotFoundError extends Error {}
const fetchPhotos = async () => {
console.info('Fetching photos...')
await new Promise((r) => setTimeout(r, 500))
return axios
.get<Array<PhotoType>>('https://jsonplaceholder.typicode.com/photos')
.then((r) => r.data.slice(0, 10))
// Generate mock photos using picsum.photos since via.placeholder.com is down
return Array.from({ length: 10 }, (_, i) => ({
id: String(i + 1),
title: `Photo ${i + 1}`,
url: `https://picsum.photos/600/400?random=${i + 1}`,
thumbnailUrl: `https://picsum.photos/200/200?random=${i + 1}`,
albumId: '1',
}))
}

const fetchPhoto = async (photoId: string) => {
console.info(`Fetching photo with id ${photoId}...`)
await new Promise((r) => setTimeout(r, 500))
const photo = await axios
.get<PhotoType>(`https://jsonplaceholder.typicode.com/photos/${photoId}`)
.then((r) => r.data)
.catch((err) => {
if (err.status === 404) {
throw new NotFoundError(`Photo with id "${photoId}" not found!`)
}
throw err
})

return photo

// Simulate photo not found for invalid IDs
const photoIdNum = parseInt(photoId, 10)
if (isNaN(photoIdNum) || photoIdNum < 1 || photoIdNum > 10) {
throw new NotFoundError(`Photo with id "${photoId}" not found!`)
}

// Generate mock photo using picsum.photos
return {
id: photoId,
title: `Photo ${photoId}`,
url: `https://picsum.photos/600/400?random=${photoId}`,
thumbnailUrl: `https://picsum.photos/200/200?random=${photoId}`,
albumId: '1',
}
}

type PhotoModal = {
Expand Down
5 changes: 5 additions & 0 deletions examples/solid/location-masking/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
11 changes: 11 additions & 0 deletions examples/solid/location-masking/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files.watcherExclude": {
"**/routeTree.gen.ts": true
},
"search.exclude": {
"**/routeTree.gen.ts": true
},
"files.readonlyInclude": {
"**/routeTree.gen.ts": true
}
}
6 changes: 6 additions & 0 deletions examples/solid/location-masking/README.md
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`
12 changes: 12 additions & 0 deletions examples/solid/location-masking/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!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>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions examples/solid/location-masking/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "tanstack-router-solid-example-location-masking",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"build": "vite build && tsc --noEmit",
"serve": "vite preview",
"start": "vite"
},
"dependencies": {
"@tailwindcss/postcss": "^4.1.15",
"@tanstack/solid-query": "^5.90.0",
"@tanstack/solid-router": "^1.135.2",
"@tanstack/solid-router-devtools": "^1.135.2",
"postcss": "^8.5.1",
"solid-js": "^1.9.10",
"redaxios": "^0.5.1",
"tailwindcss": "^4.1.15"
},
"devDependencies": {
"vite-plugin-solid": "^2.11.10",
"typescript": "^5.7.2",
"vite": "^7.1.7"
}
}
5 changes: 5 additions & 0 deletions examples/solid/location-masking/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
Loading
Loading