Commit 9cc8d26a authored by fridays's avatar fridays Committed by Arunoda Susiripala

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

parent 0f3fecfe
...@@ -18,7 +18,7 @@ export default class PageLoader { ...@@ -18,7 +18,7 @@ export default class PageLoader {
if (route[0] !== '/') { if (route[0] !== '/') {
throw new Error('Route name should start with a "/"') throw new Error('Route name should start with a "/"')
} }
route = route.replace(/index$/, '') route = route.replace(/\/index$/, '/')
if (route === '/') return route if (route === '/') return route
return route.replace(/\/$/, '') return route.replace(/\/$/, '')
......
...@@ -14,7 +14,7 @@ export default class PagesPlugin { ...@@ -14,7 +14,7 @@ export default class PagesPlugin {
pages.forEach((chunk) => { pages.forEach((chunk) => {
const page = compilation.assets[chunk.name] const page = compilation.assets[chunk.name]
const pageName = MATCH_ROUTE_NAME.exec(chunk.name)[1] 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 // We need to convert \ into / when we are in windows
// to get the proper route name // to get the proper route name
...@@ -26,6 +26,8 @@ export default class PagesPlugin { ...@@ -26,6 +26,8 @@ export default class PagesPlugin {
routeName = routeName.replace(/\\/g, '/') routeName = routeName.replace(/\\/g, '/')
} }
routeName = `/${routeName.replace(/(^|\/)index$/, '')}`
const content = page.source() const content = page.source()
const newContent = ` const newContent = `
window.__NEXT_REGISTER_PAGE('${routeName}', function() { window.__NEXT_REGISTER_PAGE('${routeName}', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment