Skip to content

Commit 3fe1d03

Browse files
Set up MPA routes in App Packages (#184)
* First pass at setting up MPA routes for the test * Format * Updated from running tests
1 parent 5b8b176 commit 3fe1d03

20 files changed

Lines changed: 300 additions & 3 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
import { testData } from '../../../testdata/src/ssr'
3+
const entries = await testData()
4+
---
5+
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width" />
10+
<title>Astro MPA Benchmark</title>
11+
</head>
12+
<body>
13+
<table>
14+
<tbody>
15+
{
16+
entries.map((entry) => (
17+
<tr>
18+
<td>{entry.id}</td>
19+
<td>{entry.name}</td>
20+
<td>
21+
<a href={`/mpa/detail?id=${entry.id}`}>View →</a>
22+
</td>
23+
</tr>
24+
))
25+
}
26+
</tbody>
27+
</table>
28+
</body>
29+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
const id = Astro.url.searchParams.get('id')
3+
---
4+
5+
<html lang="en">
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="viewport" content="width=device-width" />
9+
<title>Astro MPA Detail</title>
10+
</head>
11+
<body>
12+
<p id="detail-id">{id}</p>
13+
</body>
14+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface Props {
2+
searchParams: Promise<{ id?: string }>
3+
}
4+
5+
export default async function MpaDetailPage({ searchParams }: Props) {
6+
const { id } = await searchParams
7+
8+
return <p id="detail-id">{id}</p>
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { testData } from '../../../testdata/src/ssr'
2+
3+
export const dynamic = 'force-dynamic'
4+
5+
export default async function MpaPage() {
6+
const entries = await testData()
7+
8+
return (
9+
<table>
10+
<tbody>
11+
{entries.map((entry) => (
12+
<tr key={entry.id}>
13+
<td>{entry.id}</td>
14+
<td>{entry.name}</td>
15+
<td>
16+
<a href={`/mpa/detail?id=${entry.id}`}>View →</a>
17+
</td>
18+
</tr>
19+
))}
20+
</tbody>
21+
</table>
22+
)
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script setup lang="ts">
2+
const route = useRoute()
3+
const id = Array.isArray(route.query.id) ? route.query.id[0] : route.query.id
4+
</script>
5+
6+
<template>
7+
<p id="detail-id">{{ id }}</p>
8+
</template>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script setup lang="ts">
2+
import { testData } from '../../../../testdata/src/ssr'
3+
4+
const { data } = await useAsyncData(() => testData(), { deep: false })
5+
</script>
6+
7+
<template>
8+
<table>
9+
<tbody>
10+
<tr v-for="entry in data" :key="entry.id">
11+
<td>{{ entry.id }}</td>
12+
<td>{{ entry.name }}</td>
13+
<td>
14+
<a :href="`/mpa/detail?id=${entry.id}`">View →</a>
15+
</td>
16+
</tr>
17+
</tbody>
18+
</table>
19+
</template>

packages/app-react-router/app/routes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ export default [
66
...(isSpa ? [] : [index('routes/home.tsx')]),
77
route('/spa', 'routes/spa.tsx'),
88
route('/spa/detail', 'routes/spa.detail.tsx'),
9+
...(isSpa
10+
? []
11+
: [
12+
route('/mpa', 'routes/mpa.tsx'),
13+
route('/mpa/detail', 'routes/mpa.detail.tsx'),
14+
]),
915
] satisfies RouteConfig
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Route } from './+types/mpa.detail'
2+
3+
export async function loader({ request }: Route.LoaderArgs) {
4+
const url = new URL(request.url)
5+
const id = url.searchParams.get('id')
6+
return { id }
7+
}
8+
9+
export default function MpaDetailPage({ loaderData }: Route.ComponentProps) {
10+
return <p id="detail-id">{loaderData.id}</p>
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { testData } from '../../../testdata/src/ssr'
2+
import type { Route } from './+types/mpa'
3+
4+
export async function loader() {
5+
const data = await testData()
6+
return { data }
7+
}
8+
9+
export default function MpaPage({ loaderData }: Route.ComponentProps) {
10+
return (
11+
<table>
12+
<tbody>
13+
{loaderData.data.map((entry) => (
14+
<tr key={entry.id}>
15+
<td>{entry.id}</td>
16+
<td>{entry.name}</td>
17+
<td>
18+
<a href={`/mpa/detail?id=${entry.id}`}>View →</a>
19+
</td>
20+
</tr>
21+
))}
22+
</tbody>
23+
</table>
24+
)
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { useSearchParams } from '@solidjs/router'
2+
3+
export default function MpaDetailPage() {
4+
const [searchParams] = useSearchParams()
5+
6+
return <p id="detail-id">{searchParams.id}</p>
7+
}

0 commit comments

Comments
 (0)