diff --git a/lib/page-loader.js b/lib/page-loader.js index fdfa9bd0..e8e1a754 100644 --- a/lib/page-loader.js +++ b/lib/page-loader.js @@ -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(/\/$/, '') diff --git a/server/build/plugins/pages-plugin.js b/server/build/plugins/pages-plugin.js index 9e208764..907630e6 100644 --- a/server/build/plugins/pages-plugin.js +++ b/server/build/plugins/pages-plugin.js @@ -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() {