Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(export): fallback to empty string for basePath #11880

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
})