mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
ctx.pathname was set to url including the query of the page to prefetch therefore the page was cached with the wrong key (article%3Fid=1?id=1), and that's why the cache didn't work (right key: article?id=1)
This commit is contained in:
parent
0714300b8c
commit
b0a469233b
|
@ -11,18 +11,16 @@ export const prefetch = async href => {
|
|||
|
||||
const url = typeof href !== 'string' ? format(href) : href
|
||||
|
||||
const { pathname } = window.location
|
||||
const parsedHref = resolve(window.location.pathname, url)
|
||||
|
||||
const parsedHref = resolve(pathname, url)
|
||||
|
||||
const { query } = typeof href !== 'string' ? href : parse(url, true)
|
||||
const { query, pathname } = typeof href !== 'string' ? href : parse(url, true)
|
||||
|
||||
const Component = await Router.prefetch(parsedHref)
|
||||
|
||||
// if Component exists and has getInitialProps
|
||||
// fetch the component props (the component should save it in cache)
|
||||
if (Component && Component.getInitialProps) {
|
||||
const ctx = { pathname: href, query, isVirtualCall: true }
|
||||
const ctx = { pathname, query, isVirtualCall: true }
|
||||
await Component.getInitialProps(ctx)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue