fix: /demos/[vertical] route with Next.js 15 params await
- Fix Next.js 15 params requirement (await params) - Add minimal test for route redirect behavior - Test verifies all 4 verticals redirect correctly
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
// Next.js 15 requires params to be awaited
|
||||
export default async function DemoVerticalPage({ params }: { params: Promise<{ vertical: string }> }) {
|
||||
const { vertical } = await params;
|
||||
// Redirect to the main demos page with the vertical as query param
|
||||
redirect(`/demos?vertical=${vertical}`);
|
||||
}
|
||||
+7
-2
@@ -6,20 +6,25 @@
|
||||
"scripts": {
|
||||
"dev": "next dev -p 1284",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
"start": "next start",
|
||||
"test": "node --experimental-strip-types tests/demos-vertical.test.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google/genai": "^1.39.0",
|
||||
"@google/generative-ai": "^0.24.1",
|
||||
"@stripe/stripe-js": "^8.7.0",
|
||||
"@vapi-ai/web": "^2.5.2",
|
||||
"framer-motion": "^12.23.12",
|
||||
"next": "^15.5.3",
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1"
|
||||
"react-dom": "^19.1.1",
|
||||
"stripe": "^17.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^19.1.12",
|
||||
"@types/react-dom": "^19.1.9",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"dotenv": "^17.3.1",
|
||||
"postcss": "^8.5.6",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "^5.9.2"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Simple test for /demos/[vertical] route
|
||||
* Tests that the dynamic route properly handles vertical params and redirects
|
||||
*/
|
||||
|
||||
const VERTICALS = ['restaurant', 'real-estate', 'clinic', 'car-rental'];
|
||||
|
||||
const BASE_URL = process.env.TEST_BASE_URL || 'http://localhost:1284';
|
||||
|
||||
async function testRoute(vertical) {
|
||||
const response = await fetch(`${BASE_URL}/demos/${vertical}`, {
|
||||
redirect: 'manual' // Don't follow redirect, just get the location
|
||||
});
|
||||
|
||||
// Should return a 307 redirect (temporary redirect in Next.js)
|
||||
if (response.status !== 307 && response.status !== 302) {
|
||||
throw new Error(`Expected 307/302 for /demos/${vertical}, got ${response.status}`);
|
||||
}
|
||||
|
||||
// Should redirect to /demos?vertical=<vertical>
|
||||
const location = response.headers.get('location');
|
||||
if (!location || !location.includes(`/demos?vertical=${vertical}`)) {
|
||||
throw new Error(`Expected redirect to /demos?vertical=${vertical}, got ${location}`);
|
||||
}
|
||||
|
||||
console.log(`✓ /demos/${vertical} redirects to ${location}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function runTests() {
|
||||
console.log('Testing /demos/[vertical] route...\n');
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
for (const vertical of VERTICALS) {
|
||||
try {
|
||||
await testRoute(vertical);
|
||||
passed++;
|
||||
} catch (error) {
|
||||
console.error(`✗ /demos/${vertical} failed: ${error.message}`);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
||||
|
||||
if (failed > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
runTests();
|
||||
Reference in New Issue
Block a user