Unverified Commit 4238878c authored by Slawek Kolodziej's avatar Slawek Kolodziej Committed by GitHub

Make sure that params are properly passed to hybrid amp pages (#17461)

Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent ee0a4a70
......@@ -352,7 +352,8 @@ export default async function exportPage({
if (serverless) {
req.url += (req.url!.includes('?') ? '&' : '?') + 'amp=1'
// @ts-ignore
ampHtml = (await renderMethod(req, res, 'export')).html
ampHtml = (await renderMethod(req, res, 'export', undefined, params))
.html
} else {
ampHtml = await renderMethod(
req,
......
......@@ -4,9 +4,10 @@ export const config = {
amp: 'hybrid',
}
export const getStaticProps = () => {
export const getStaticProps = (ctx) => {
return {
props: {
slug: ctx.params?.slug || null,
hello: 'hello',
random: Math.random(),
},
......@@ -18,10 +19,11 @@ export const getStaticPaths = () => ({
fallback: false,
})
export default ({ hello, random }) => (
export default ({ hello, random, slug }) => (
<>
<p id="use-amp">useAmp: {useAmp() ? 'yes' : 'no'}</p>
<p id="hello">{hello}</p>
<p id="random">{random}</p>
<p id="slug">{slug}</p>
</>
)
......@@ -51,6 +51,7 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('no')
expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
})
it('should load dynamic hybrid SSG/AMP page with trailing slash', async () => {
......@@ -58,6 +59,7 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('no')
expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
})
it('should load dynamic hybrid SSG/AMP page with query', async () => {
......@@ -65,6 +67,7 @@ const runTests = (isDev = false) => {
const $ = cheerio.load(html)
expect($('#use-amp').text()).toContain('yes')
expect($('#hello').text()).toContain('hello')
expect($('#slug').text()).toContain('post-1')
})
it('should load a hybrid amp page with query correctly', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment