6c7e76b551
This adapts the new client hooks of `usePathname`, `useSearchParams`, and `useRouter` to work within the `pages/` directory to aid users attempting to migrate shared components over to the `app/` directory. > **Exception:** > When the pages router is not ready, `useSearchParams` will return an empty `URLSearchParams`. This mirrors the behavior seen in the `pages/` directory today in that `router.query` is not available until the client hydrates. This also adds a new option for `useRouter` to bring it line with the correct typings with the app directory. By default, calling `useRouter()` will return the type `NextRouter | null` to represent what you get when you call it from a component originating from the app directory. If you want to instead force it to return `NextRouter` as it does today, you can pass a boolean into the `useRouter` call as such: ```ts const router = useRouter() // typeof router === NextRouter | null const router = useRouter(true) // typeof router === NextRouter ``` This change is designed to ease the incremental adoption of app. |
||
---|---|---|
.. | ||
i18n | ||
isomorphic | ||
page-path | ||
router | ||
utils | ||
amp-context.ts | ||
amp-mode.ts | ||
amp.ts | ||
app-router-context.ts | ||
constants.ts | ||
dynamic.tsx | ||
escape-regexp.ts | ||
flatten.ts | ||
get-hostname.ts | ||
head-manager-context.ts | ||
head.tsx | ||
hooks-client-context.ts | ||
html-context.ts | ||
image-blur-svg.ts | ||
image-config-context.ts | ||
image-config.ts | ||
image-loader.ts | ||
is-plain-object.ts | ||
loadable-context.ts | ||
loadable.d.ts | ||
loadable.js | ||
match-remote-pattern.ts | ||
mitt.ts | ||
router-context.ts | ||
runtime-config.ts | ||
server-inserted-html.tsx | ||
side-effect.tsx | ||
styled-jsx.d.ts | ||
styled-jsx.js | ||
utils.ts |