Skip to content

Conversation

@fridays
Copy link
Contributor

@fridays fridays commented Jul 8, 2017

Client navigation currently fails if the filename of a page ends with *index
It happens in both v2 and v3

Reproduce the issue:

// pages/index.js
import Link from 'next/link'
export default () => <Link href='/abcindex'><a>go</a></Link>

// pages/abcindex.js
export default () => <div>abc</div>
  1. Open /
  2. Click the link
  3. See 404 error instead of page

This PR fixes it by changing two regular expressions.

throw new Error('Route name should start with a "/"')
}
route = route.replace(/index$/, '')
route = route.replace(/\/index$/, '/')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this received /abcindex and produced /abc
Now it only matches /index or /abc/index

routeName = routeName.replace(/\\/g, '/')
}

routeName = `/${routeName.replace(/(^|\/)index$/, '')}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this receiced abcindex and produced /abc
Now it only matches index or abc/index
And it does that after the windows slash conversion

@arunoda
Copy link
Contributor

arunoda commented Jul 9, 2017

This fix looks solid. Thanks.

@arunoda arunoda merged commit 9cc8d26 into vercel:master Jul 9, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jul 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants