Custom routes and 404 on client side getServerSideProps access
See original GitHub issueBug report
Describe the bug
I’m using custom routes to make translated paths (/hello, /hola, /ni-hao) for my server-side rendered pages (/hi/[lang].js).
I then link to them like this:
<Link href="/hi/[lang]?lang=zh" as="/ni-hao">...</Link>
Unexpectedly though, a click on that link tries to load the data from getServerSideProps by requesting _next/data/.../ni-hao.json instead of _next/data/.../hi/[lang].json
To Reproduce
Repo: https://github.com/davidknezic/now-nextjs-issues/tree/now-nextjs-rewrites Live: https://now-nextjs-issues-git-now-nextjs-rewrites.davidknezic.vercel.app
next.config.js
module.exports = {
target: 'serverless',
experimental: {
async rewrites () {
return [
{ source: '/hello', destination: '/hi/en' },
{ source: '/hola', destination: '/hi/es' },
{ source: '/ni-hao', destination: '/hi/zh' }
]
}
}
}
pages/index.js
<Link href="/hi/[lang]?lang=zh" as="/ni-hao">
<a>ni hao</a>
</Link>
pages/hi/[lang].js
export default function Index () {
return (
<h1>hi</h1>
)
}
export async function getServerSideProps () {
return {
props: {}
}
}
Expected behavior
I’d expect Next.js to fetch server side data based on the links href instead of the as param.
System information
- OS: any
- Browser: any
- Version of Next.js: 9.3.1
Additional context
I host all of this with Now, which currently doesn’t seem to understand Next.js rewrites, both in dev and productively. Is it planned to introduce this?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
I was able to make it work by changing
this._getServerData(as)tothis._getServerData(pathname)in my local next.js repo:https://github.com/zeit/next.js/blob/cadc950e2d2eea969ddabf135e9223b2c21108d6/packages/next/next-server/lib/router/router.ts#L618-L624
this._getStaticData(as)also uses theasparam. However, there it might be on purpose.This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.