diff --git a/lib/page-loader.js b/lib/page-loader.js index 8a47076f..fdfa9bd0 100644 --- a/lib/page-loader.js +++ b/lib/page-loader.js @@ -18,9 +18,10 @@ export default class PageLoader { if (route[0] !== '/') { throw new Error('Route name should start with a "/"') } + route = route.replace(/index$/, '') if (route === '/') return route - return route.replace(/index$/, '').replace(/\/$/, '') + return route.replace(/\/$/, '') } loadPage (route) { diff --git a/test/integration/basic/pages/index.js b/test/integration/basic/pages/index.js new file mode 100644 index 00000000..b6724fea --- /dev/null +++ b/test/integration/basic/pages/index.js @@ -0,0 +1,2 @@ +import CDM from '../lib/cdm' +export default CDM diff --git a/test/integration/basic/test/client-navigation.js b/test/integration/basic/test/client-navigation.js index 3b4c3539..898737d0 100644 --- a/test/integration/basic/test/client-navigation.js +++ b/test/integration/basic/test/client-navigation.js @@ -323,7 +323,7 @@ export default (context, render) => { }) describe('with different types of urls', () => { - it('on normal page', async () => { + it('should work with normal page', async () => { const browser = await webdriver(context.appPort, '/with-cdm') const text = await browser.elementByCss('p').text() @@ -331,7 +331,7 @@ export default (context, render) => { browser.close() }) - it('on dir/index page ', async () => { + it('should work with dir/index page ', async () => { const browser = await webdriver(context.appPort, '/nested-cdm/index') const text = await browser.elementByCss('p').text() @@ -339,13 +339,29 @@ export default (context, render) => { browser.close() }) - it('on dir/ page ', async () => { + it('should work with dir/ page ', async () => { const browser = await webdriver(context.appPort, '/nested-cdm/') const text = await browser.elementByCss('p').text() expect(text).toBe('ComponentDidMount executed on client.') browser.close() }) + + it('should work with /index page', async () => { + const browser = await webdriver(context.appPort, '/index') + const text = await browser.elementByCss('p').text() + + expect(text).toBe('ComponentDidMount executed on client.') + browser.close() + }) + + it('should work with / page', async () => { + const browser = await webdriver(context.appPort, '/') + const text = await browser.elementByCss('p').text() + + expect(text).toBe('ComponentDidMount executed on client.') + browser.close() + }) }) describe('with asPath', () => {