Skip to content
Open
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
11 changes: 11 additions & 0 deletions e2e/preact-router/basic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
.DS_Store
dist
dist-hash
dist-ssr
*.local

/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
12 changes: 12 additions & 0 deletions e2e/preact-router/basic/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>TanStack Router Preact E2E</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions e2e/preact-router/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "tanstack-router-e2e-preact-basic",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"dev:e2e": "vite",
"build": "vite build && tsc --noEmit",
"preview": "vite preview",
"start": "vite",
"test:e2e": "rm -rf port*.txt; playwright test --project=chromium"
},
"dependencies": {
"@tanstack/preact-router": "workspace:^",
"preact": "^10.25.0",
"preact-render-to-string": "^6.6.5"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
"@preact/preset-vite": "^2.9.4",
"@tanstack/router-e2e-utils": "workspace:^",
"typescript": "^5.9.3",
"vite": "^7.3.1"
}
}
33 changes: 33 additions & 0 deletions e2e/preact-router/basic/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineConfig, devices } from '@playwright/test'
import {
getDummyServerPort,
getTestServerPort,
} from '@tanstack/router-e2e-utils'
import packageJson from './package.json' with { type: 'json' }

const PORT = await getTestServerPort(packageJson.name)
const EXTERNAL_PORT = await getDummyServerPort(packageJson.name)
const baseURL = `http://localhost:${PORT}`

export default defineConfig({
testDir: './tests',
workers: 1,
reporter: [['line']],
globalSetup: './tests/setup/global.setup.ts',
globalTeardown: './tests/setup/global.teardown.ts',
use: {
baseURL,
},
webServer: {
command: `VITE_NODE_ENV=\"test\" VITE_SERVER_PORT=${PORT} VITE_EXTERNAL_PORT=${EXTERNAL_PORT} pnpm build && pnpm preview --port ${PORT}`,
url: baseURL,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
})
67 changes: 67 additions & 0 deletions e2e/preact-router/basic/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { render } from 'preact'
import { useMemo } from 'preact/hooks'
import {
Await,
Link,
Outlet,
RouterProvider,
Suspense,
createRootRoute,
createRoute,
createRouter,
} from '@tanstack/preact-router'

const rootRoute = createRootRoute({
component: () => (
<div>
<nav>
<Link to="/" activeOptions={{ exact: true }}>
Home
</Link>{' '}
<Link to="/slow">Slow</Link>
</nav>
<Outlet />
</div>
),
})

const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: () => <h1 data-testid="home">Home</h1>,
})

const slowRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/slow',
component: SlowRouteComponent,
})

function SlowRouteComponent() {
const promise = useMemo(
() =>
new Promise<string>((resolve) => {
setTimeout(() => resolve('Loaded!'), 200)
}),
[],
)

return (
<div>
<h1 data-testid="slow-title">Slow Route</h1>
<Suspense fallback={<div data-testid="suspense-fallback">Loading...</div>}>
<Await promise={promise}>
{(value) => <div data-testid="suspense-content">{value}</div>}
</Await>
</Suspense>
</div>
)
}

const routeTree = rootRoute.addChildren([indexRoute, slowRoute])

const router = createRouter({
routeTree,
})

render(<RouterProvider router={router} />, document.getElementById('app')!)
14 changes: 14 additions & 0 deletions e2e/preact-router/basic/tests/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, test } from '@playwright/test'

test.beforeEach(async ({ page }) => {
await page.goto('/')
})

test('shows suspense fallback and then resolved content', async ({ page }) => {
Copy link

@Hardanish-Singh Hardanish-Singh Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit]: test('shows suspense fallback and then resolves content', async ({ page }) => { .... }

await expect(page.getByTestId('home')).toBeVisible()

await page.getByRole('link', { name: 'Slow' }).click()
await expect(page.getByTestId('slow-title')).toBeVisible()
await expect(page.getByTestId('suspense-fallback')).toBeVisible()
await expect(page.getByTestId('suspense-content')).toHaveText('Loaded!')
})
6 changes: 6 additions & 0 deletions e2e/preact-router/basic/tests/setup/global.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { e2eStartDummyServer } from '@tanstack/router-e2e-utils'
import packageJson from '../../package.json' with { type: 'json' }

export default async function setup() {
await e2eStartDummyServer(packageJson.name)
}
6 changes: 6 additions & 0 deletions e2e/preact-router/basic/tests/setup/global.teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { e2eStopDummyServer } from '@tanstack/router-e2e-utils'
import packageJson from '../../package.json' with { type: 'json' }

export default async function teardown() {
await e2eStopDummyServer(packageJson.name)
}
20 changes: 20 additions & 0 deletions e2e/preact-router/basic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"baseUrl": ".",
"strict": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"jsxImportSource": "preact",
"target": "ESNext",
"moduleResolution": "Bundler",
"module": "ESNext",
"resolveJsonModule": true,
"allowJs": true,
"skipLibCheck": true,
"types": ["vite/client"],
"paths": {
"@tanstack/router-e2e-utils": ["../../e2e-utils/src/index.ts"]
}
},
"exclude": ["node_modules", "dist"]
}
6 changes: 6 additions & 0 deletions e2e/preact-router/basic/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'

export default defineConfig({
plugins: [preact()],
})
10 changes: 10 additions & 0 deletions examples/preact/basic/.gitignore
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/
11 changes: 11 additions & 0 deletions examples/preact/basic/.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
}
}
45 changes: 45 additions & 0 deletions examples/preact/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# TanStack Router - Basic Example

A basic example demonstrating the fundamentals of TanStack Router.

- [TanStack Router Docs](https://tanstack.com/router)

## Start a new project based on this example

To start a new project based on this example, run:

```sh
npx gitpick TanStack/router/tree/main/examples/react/basic basic
```

## Getting Started

Install dependencies:

```sh
pnpm install
```

Start the development server:

```sh
pnpm dev
```

## Build

Build for production:

```sh
pnpm build
```

## About This Example

This example demonstrates:

- Basic routing setup
- Route configuration
- Navigation
- Route parameters
- TanStack Router DevTools
12 changes: 12 additions & 0 deletions examples/preact/basic/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>
24 changes: 24 additions & 0 deletions examples/preact/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "tanstack-router-react-example-basic",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --port=3000",
"build": "vite build && tsc --noEmit",
"preview": "vite preview",
"start": "vite"
},
"dependencies": {
"@tailwindcss/vite": "^4.1.18",
"@tanstack/preact-router": "^1.160.0",
"preact": "^10.25.0",
"preact-render-to-string": "^6.6.5",
"redaxios": "^0.5.1",
"tailwindcss": "^4.1.18"
},
"devDependencies": {
"@preact/preset-vite": "^2.10.3",
"typescript": "^5.7.2",
"vite": "^7.3.1"
}
}
Loading