Unverified Commit 916e21f9 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update manual basePath with trailingSlash (#51726)

With the manualBasePath config we still need to normalize the trailing
slash per that config.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1687543336964799?thread_ts=1687487533.019499&cid=C03S8ED1DKM)
parent ae4a7234
...@@ -4,11 +4,9 @@ import { normalizePathTrailingSlash } from './normalize-trailing-slash' ...@@ -4,11 +4,9 @@ import { normalizePathTrailingSlash } from './normalize-trailing-slash'
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || '' const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
export function addBasePath(path: string, required?: boolean): string { export function addBasePath(path: string, required?: boolean): string {
if (process.env.__NEXT_MANUAL_CLIENT_BASE_PATH) { return normalizePathTrailingSlash(
if (!required) { process.env.__NEXT_MANUAL_CLIENT_BASE_PATH && !required
return path ? path
} : addPathPrefix(path, basePath)
} )
return normalizePathTrailingSlash(addPathPrefix(path, basePath))
} }
...@@ -32,6 +32,11 @@ export default function Page(props) { ...@@ -32,6 +32,11 @@ export default function Page(props) {
</Link> </Link>
<br /> <br />
<Link href="/another/" id="to-another-slash">
to /another
</Link>
<br />
<Link href="/dynamic/first" id="to-dynamic"> <Link href="/dynamic/first" id="to-dynamic">
to /dynamic/first to /dynamic/first
</Link> </Link>
......
...@@ -159,6 +159,14 @@ describe('manual-client-base-path', () => { ...@@ -159,6 +159,14 @@ describe('manual-client-base-path', () => {
await check(() => browser.elementByCss('#page').text(), 'index page') await check(() => browser.elementByCss('#page').text(), 'index page')
expect(await browser.eval('window.location.pathname')).toBe('/') expect(await browser.eval('window.location.pathname')).toBe('/')
await browser.elementByCss('#to-another-slash').click()
await check(() => browser.elementByCss('#page').text(), 'another page')
expect(await browser.eval('window.location.pathname')).toBe('/another')
await browser.back()
await check(() => browser.elementByCss('#page').text(), 'index page')
expect(await browser.eval('window.location.pathname')).toBe('/')
await browser.elementByCss('#to-dynamic').click() await browser.elementByCss('#to-dynamic').click()
await check(() => browser.elementByCss('#page').text(), 'dynamic page') await check(() => browser.elementByCss('#page').text(), 'dynamic page')
expect(await browser.eval('window.location.pathname')).toBe( expect(await browser.eval('window.location.pathname')).toBe(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment