diff --git a/lib/page-loader.js b/lib/page-loader.js index 6ec0c2bc..8a47076f 100644 --- a/lib/page-loader.js +++ b/lib/page-loader.js @@ -19,7 +19,8 @@ export default class PageLoader { throw new Error('Route name should start with a "/"') } - return route.replace(/index$/, '') + if (route === '/') return route + return route.replace(/index$/, '').replace(/\/$/, '') } loadPage (route) { diff --git a/test/integration/basic/lib/cdm.js b/test/integration/basic/lib/cdm.js new file mode 100644 index 00000000..773e705e --- /dev/null +++ b/test/integration/basic/lib/cdm.js @@ -0,0 +1,19 @@ +import React, {Component} from 'react' + +export default class extends Component { + constructor (props) { + super(props) + + this.state = { + mounted: false + } + } + + componentDidMount () { + this.setState({mounted: true}) + } + + render () { + return

ComponentDidMount {this.state.mounted ? 'executed on client' : 'not executed'}.

+ } +} diff --git a/test/integration/basic/pages/nested-cdm/index.js b/test/integration/basic/pages/nested-cdm/index.js new file mode 100644 index 00000000..3613e758 --- /dev/null +++ b/test/integration/basic/pages/nested-cdm/index.js @@ -0,0 +1,2 @@ +import CDM from '../../lib/cdm' +export default CDM diff --git a/test/integration/basic/pages/with-cdm.js b/test/integration/basic/pages/with-cdm.js new file mode 100644 index 00000000..b6724fea --- /dev/null +++ b/test/integration/basic/pages/with-cdm.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 2f4a187f..b33d8be6 100644 --- a/test/integration/basic/test/client-navigation.js +++ b/test/integration/basic/test/client-navigation.js @@ -321,5 +321,31 @@ export default (context, render) => { browser.close() }) }) + + describe('with different types of urls', () => { + it('on normal page', async () => { + const browser = await webdriver(context.appPort, '/with-cdm') + const text = await browser.elementByCss('p').text() + + expect(text).toBe('ComponentDidMount executed on client.') + browser.close() + }) + + it('on dir/index page ', async () => { + const browser = await webdriver(context.appPort, '/nested-cdm/index') + const text = await browser.elementByCss('p').text() + + expect(text).toBe('ComponentDidMount executed on client.') + browser.close() + }) + + it('on 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() + }) + }) }) } diff --git a/test/integration/basic/test/index.test.js b/test/integration/basic/test/index.test.js index d7a7d5a1..8ece248a 100644 --- a/test/integration/basic/test/index.test.js +++ b/test/integration/basic/test/index.test.js @@ -42,6 +42,7 @@ describe('Basic Features', () => { renderViaHTTP(context.appPort, '/stateful'), renderViaHTTP(context.appPort, '/stateless'), renderViaHTTP(context.appPort, '/styled-jsx'), + renderViaHTTP(context.appPort, '/with-cdm'), renderViaHTTP(context.appPort, '/nav'), renderViaHTTP(context.appPort, '/nav/about'), @@ -49,7 +50,9 @@ describe('Basic Features', () => { renderViaHTTP(context.appPort, '/nav/self-reload'), renderViaHTTP(context.appPort, '/nav/hash-changes'), renderViaHTTP(context.appPort, '/nav/shallow-routing'), - renderViaHTTP(context.appPort, '/nav/redirect') + renderViaHTTP(context.appPort, '/nav/redirect'), + + renderViaHTTP(context.appPort, '/nested-cdm/index') ]) }) afterAll(() => stopApp(context.server))