Skip to content

Commit

Permalink
fix(export): fallback to empty string for basePath (#11880)
Browse files Browse the repository at this point in the history
* fix(next-server): fallback to empty string for basePath

* Revert extra change and add unit test

Co-authored-by: JJ Kasper <[email protected]>
  • Loading branch information
Fonger and ijjk authored Apr 14, 2020
1 parent ab18c79 commit 5248e18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isDynamicRoute } from './utils/is-dynamic'
import { getRouteMatcher } from './utils/route-matcher'
import { getRouteRegex } from './utils/route-regex'

const basePath = process.env.__NEXT_ROUTER_BASEPATH as string
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''

export function addBasePath(path: string): string {
return path.indexOf(basePath) !== 0 ? basePath + path : path
Expand Down
9 changes: 9 additions & 0 deletions test/unit/router-add-base-path.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-env jest */
import { addBasePath } from 'next/dist/next-server/lib/router/router'

describe('router addBasePath', () => {
it('should add basePath correctly when no basePath', () => {
const result = addBasePath('/hello')
expect(result).toBe('/hello')
})
})

0 comments on commit 5248e18

Please sign in to comment.