forked from vercel/turborepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ctx.params in getStaticProps/getServerSideProps (verc…
…el#3696) Dynamic segments should be passed a single string, while catch-all segments should be passed a list of strings. Furthermore, ctx.params was previously undefined because we weren't passing it forward through the render options.
- Loading branch information
Showing
10 changed files
with
123 additions
and
14 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
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
26 changes: 26 additions & 0 deletions
26
...xt-dev-tests/tests/integration/next/router/catch-all-params/input/pages/[...segments].tsx
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,26 @@ | ||
import { useEffect } from "react"; | ||
|
||
export default function Home({ params }: { params: any }) { | ||
useEffect(() => { | ||
// Only run on client | ||
import("@turbo/pack-test-harness").then(() => runTests(params)); | ||
}); | ||
|
||
return <div>Test</div>; | ||
} | ||
|
||
export function getServerSideProps(ctx: { params: any }) { | ||
return { | ||
props: { | ||
params: ctx.params, | ||
}, | ||
}; | ||
} | ||
|
||
function runTests(params: any) { | ||
describe("catch-all segments", () => { | ||
it("should be passed a param array", () => { | ||
expect(params.segments).toEqual(["first", "second"]); | ||
}); | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/next-dev-tests/tests/integration/next/router/catch-all-params/input/pages/index.tsx
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,7 @@ | ||
export function getServerSideProps() { | ||
return { | ||
redirect: { | ||
destination: "/first/second", | ||
}, | ||
}; | ||
} |
26 changes: 26 additions & 0 deletions
26
crates/next-dev-tests/tests/integration/next/router/dynamic-params/input/pages/[segment].tsx
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,26 @@ | ||
import { useEffect } from "react"; | ||
|
||
export default function Home({ params }: { params: any }) { | ||
useEffect(() => { | ||
// Only run on client | ||
import("@turbo/pack-test-harness").then(() => runTests(params)); | ||
}); | ||
|
||
return <div>Test</div>; | ||
} | ||
|
||
export function getServerSideProps(ctx: { params: any }) { | ||
return { | ||
props: { | ||
params: ctx.params, | ||
}, | ||
}; | ||
} | ||
|
||
function runTests(params: any) { | ||
describe("catch-all segments", () => { | ||
it("should be passed a param array", () => { | ||
expect(params.segment).toEqual("dynamic-segment"); | ||
}); | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/next-dev-tests/tests/integration/next/router/dynamic-params/input/pages/index.tsx
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,7 @@ | ||
export function getServerSideProps() { | ||
return { | ||
redirect: { | ||
destination: "/dynamic-segment", | ||
}, | ||
}; | ||
} |
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