Open rakeshtembhurne opened 1 year ago
I had to add extra code when in AMP mode, to make it work like normal:
export async function getServerSideProps() {
return { props: {} }
}
Solves my issue, but unsure if it is the right solution for the problem. Either it should be documented or a fix still needs to be worked out.
@rakeshtembhurne can you suggest me how to do it in app router?
Link to the code that reproduces this issue or a replay of the bug
https://github.com/rakeshtembhurne/next-router-amp-dynamic-routes
To Reproduce
stories/[...slug].tsx
export const config = { amp: true}
import { useRouter } from "next/router"
andconst router = useRouter();
http://localhost:3000/stories/some-random-story
router
as JSON<pre>{JSON.stringify(router, null, 2)}</pre>
, in both cases value ofslug
is missing inquery
Current vs. Expected behavior
Expected Output
When visiting url:
http://localhost:3000/stories/inside/some-random-story
, we should get valuerouter.query.slug === "some-random-story"
whether amp is enabled or not.Current Behavior
Case "Without exporting config variable (normally)"
console.log({ asPath, pathname, route, query });
<pre>{JSON.stringify({ asPath, pathname, route, query }, null, 2)}</pre>
Case "with
export const config = { amp: true}
"console.log({ asPath, pathname, route, query });
<pre>{JSON.stringify({ asPath, pathname, route, query }, null, 2)}</pre>
Case "with
export const config = { amp:'hybrid'}
AND?amp=1
at the end of URL"console.log({ asPath, pathname, route, query });
<pre>{JSON.stringify({ asPath, pathname, route, query }, null, 2)}</pre>
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
App Router, Routing (next/router, next/navigation, next/link)
Additional context
No response