Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0edee47

Browse files
arunodarauchg
authored andcommitted
Fix the page-loader-normalization issue on '/index' page. (vercel#1882)
1 parent 68880bc commit 0edee47

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

lib/page-loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export default class PageLoader {
1818
if (route[0] !== '/') {
1919
throw new Error('Route name should start with a "/"')
2020
}
21+
route = route.replace(/index$/, '')
2122

2223
if (route === '/') return route
23-
return route.replace(/index$/, '').replace(/\/$/, '')
24+
return route.replace(/\/$/, '')
2425
}
2526

2627
loadPage (route) {

test/integration/basic/pages/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import CDM from '../lib/cdm'
2+
export default CDM

test/integration/basic/test/client-navigation.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,29 +323,45 @@ export default (context, render) => {
323323
})
324324

325325
describe('with different types of urls', () => {
326-
it('on normal page', async () => {
326+
it('should work with normal page', async () => {
327327
const browser = await webdriver(context.appPort, '/with-cdm')
328328
const text = await browser.elementByCss('p').text()
329329

330330
expect(text).toBe('ComponentDidMount executed on client.')
331331
browser.close()
332332
})
333333

334-
it('on dir/index page ', async () => {
334+
it('should work with dir/index page ', async () => {
335335
const browser = await webdriver(context.appPort, '/nested-cdm/index')
336336
const text = await browser.elementByCss('p').text()
337337

338338
expect(text).toBe('ComponentDidMount executed on client.')
339339
browser.close()
340340
})
341341

342-
it('on dir/ page ', async () => {
342+
it('should work with dir/ page ', async () => {
343343
const browser = await webdriver(context.appPort, '/nested-cdm/')
344344
const text = await browser.elementByCss('p').text()
345345

346346
expect(text).toBe('ComponentDidMount executed on client.')
347347
browser.close()
348348
})
349+
350+
it('should work with /index page', async () => {
351+
const browser = await webdriver(context.appPort, '/index')
352+
const text = await browser.elementByCss('p').text()
353+
354+
expect(text).toBe('ComponentDidMount executed on client.')
355+
browser.close()
356+
})
357+
358+
it('should work with / page', async () => {
359+
const browser = await webdriver(context.appPort, '/')
360+
const text = await browser.elementByCss('p').text()
361+
362+
expect(text).toBe('ComponentDidMount executed on client.')
363+
browser.close()
364+
})
349365
})
350366

351367
describe('with asPath', () => {

0 commit comments

Comments
 (0)