mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
74a19b7467
## Summary Remove redundant `#` from [error pages](https://github.com/vercel/next.js/tree/canary/errors). ## Description Follow up #52038 and #72263. Updated [template.txt](https://github.com/vercel/next.js/blob/canary/errors/template.txt) and clarified the header deps. Then rewrite as per the template. ### Improving Documentation - [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
34 lines
1.3 KiB
Plaintext
34 lines
1.3 KiB
Plaintext
---
|
|
title: '`Router.onAppUpdated` has been removed'
|
|
---
|
|
|
|
## Why This Error Occurred
|
|
|
|
Due to [this bug fix](https://github.com/vercel/next.js/pull/3849), we had to remove the `Router.onAppUpdated` hook. But the default functionality of this feature is still in effect.
|
|
|
|
We use this hook to detect a new app deployment when switching pages and act accordingly.
|
|
|
|
Although there are many things you can do in this hook, it's often used to navigate the page via the server as shown below:
|
|
|
|
```js filename="example.js"
|
|
Router.onAppUpdated = function (nextRoute) {
|
|
location.href = nextRoute
|
|
}
|
|
```
|
|
|
|
In this hook, you can't wait for a network request or a promise to get resolved. And you can't block the page navigation. So, the things you can do is limited.
|
|
|
|
## Possible Ways to Fix It
|
|
|
|
One real use of this hook is to persist your application state to local-storage before the page navigation. For that, you can use the [`window.onbeforeunload`](https://developer.mozilla.org/docs/Web/API/WindowEventHandlers/onbeforeunload) hook instead.
|
|
|
|
This is code for that:
|
|
|
|
```js filename="example.js"
|
|
window.onbeforeunload = function (e) {
|
|
// Get the application state (usually from a store like Redux)
|
|
const appState = {}
|
|
localStorage.setItem('app-state', JSON.stringify(appState))
|
|
}
|
|
```
|