Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regex for pages that end with index #2505

Merged
merged 1 commit into from
Jul 9, 2017
Merged

fix regex for pages that end with index #2505

merged 1 commit into from
Jul 9, 2017

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.

@@ -18,7 +18,7 @@ export default class PageLoader {
if (route[0] !== '/') {
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

@@ -26,6 +26,8 @@ export default class PagesPlugin {
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