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

Avoid adding basePath when it's not needed #14535

Merged
merged 5 commits into from
Jun 25, 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
3 changes: 2 additions & 1 deletion packages/next/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RouterContext } from '../next-server/lib/router-context'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
import * as envConfig from '../next-server/lib/runtime-config'
import { getURL, loadGetInitialProps, ST } from '../next-server/lib/utils'
import { delBasePath } from '../next-server/lib/router/router'
import initHeadManager from './head-manager'
import PageLoader from './page-loader'
import measureWebVitals from './performance-relayer'
Expand Down Expand Up @@ -48,7 +49,7 @@ envConfig.setConfig({
publicRuntimeConfig: runtimeConfig || {},
})

const asPath = getURL()
const asPath = delBasePath(getURL())

const pageLoader = new PageLoader(buildId, prefix, page)
const register = ([r, f]) => pageLoader.registerPage(r, f)
Expand Down
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 @@ -263,7 +263,7 @@ export default class Router implements BaseRouter {
this.changeState(
'replaceState',
formatWithValidation({ pathname: addBasePath(pathname), query }),
as
addBasePath(as)
)
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/basepath/pages/[slug].js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { useRouter } from 'next/router'

export default () => <p>slug: {useRouter().query.slug}</p>
export default () => <p id="slug">slug: {useRouter().query.slug}</p>
6 changes: 6 additions & 0 deletions test/integration/basepath/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ const runTests = (context, dev = false) => {
})
}

it('should update dynamic params after mount correctly', async () => {
const browser = await webdriver(context.appPort, '/docs/hello-dynamic')
const text = await browser.elementByCss('#slug').text()
expect(text).toContain('slug: hello-dynamic')
})

it('should navigate to index page with getStaticProps', async () => {
const browser = await webdriver(context.appPort, '/docs/hello')
await browser.eval('window.beforeNavigate = "hi"')
Expand Down