1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

fix regex for pages that end with index (#2505)

This commit is contained in:
fridays 2017-07-09 06:20:30 +02:00 committed by Arunoda Susiripala
parent 0f3fecfe8b
commit 9cc8d26a68
2 changed files with 4 additions and 2 deletions

View file

@ -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$/, '/')
if (route === '/') return route
return route.replace(/\/$/, '')

View file

@ -14,7 +14,7 @@ export default class PagesPlugin {
pages.forEach((chunk) => {
const page = compilation.assets[chunk.name]
const pageName = MATCH_ROUTE_NAME.exec(chunk.name)[1]
let routeName = `/${pageName.replace(/[/\\]?index$/, '')}`
let routeName = pageName
// We need to convert \ into / when we are in windows
// to get the proper route name
@ -26,6 +26,8 @@ export default class PagesPlugin {
routeName = routeName.replace(/\\/g, '/')
}
routeName = `/${routeName.replace(/(^|\/)index$/, '')}`
const content = page.source()
const newContent = `
window.__NEXT_REGISTER_PAGE('${routeName}', function() {