From 0edee47d0778d5a94fd66d2f461dcfcd0a99a474 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Thu, 4 May 2017 13:05:47 -0700 Subject: [PATCH] Fix the page-loader-normalization issue on '/index' page. (#1882) --- lib/page-loader.js | 3 ++- test/integration/basic/pages/index.js | 2 ++ .../basic/test/client-navigation.js | 22 ++++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test/integration/basic/pages/index.js 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', () => {