Skip to content

Using getStaticPaths in combination with trailingSlash: true leads to invalid json prefetching #17813

@bram-l

Description

@bram-l

Bug report

Using getStaticPaths in combination with trailingSlash: true leads to invalid json prefetching. For a link to a dynamic route, the json file that is prefetched includes an invalid slash in the path, causing a 404 to be returned. However, when clicking the link and landing on the dynamic page the correct json file is fetched.

To Reproduce

  1. Configure
// next.config.js
module.exports = {
  trailingSlash: true,
};
  1. Add dynamic route
// pages/[name].js
export default function Hello({ name }) {
  return <div>Hello {name}</div>
}

export function getStaticProps(context) {
  return {
    props: {
      name: context.params.name
    }
  };
}

export function getStaticPaths() {
  return {
    paths: [
      { params: { name: 'world' } }
    ],
    fallback: false
  };
}
  1. Add link to dynamic route
// pages/index.js
import Link from 'next/link'
export default function Home() {
  return (
    <div>
      <Link as="/world" href="/[name]">
        <a>Hello world</a>
      </Link>
    </div>
  )
}
  1. Export using next build && next export
  2. Open root page
  3. Observe a network request for https://example.com/_next/data/some-hash/world/.json returning a 404

Expected behavior

The correct https://example.com/_next/data/some-hash/world.json is (pre)fetched

System information

  • OS: macOs
  • Browser (if applies): chrome
  • Version of Next.js: 9.5.5
  • Version of Node.js: v12.18.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions