---
name: "onPageNotFound"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.10.0" }
title: "ty.onPageNotFound"
---

## onPageNotFound

> [VERSION] Base Library >= 2.10.0

### Description

Listen for the event when the Mini Program attempts to open a non-existent page. Its callback timing is consistent with App.onPageNotFound.

### Parameters

`(callback: Function)`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `callback` | `(res: OnPageNotFoundCallbackResult) => void` | Yes | Callback for the event when the Mini Program attempts to open a non-existent page |

### Return Value

None


### Referenced Types

##### `interface` OnPageNotFoundCallbackResult

| Property | Type | Required | Description |
| --- | --- | --- | --- |
| `url` | `string` | Yes | Path of the non-existent page (bundle path) |
| `query` | `Record<string, string>` | Yes | Query parameters used to open the non-existent page |


### Examples

#### Listen for page-not-found events

```js
// app.js
App({
  onLaunch() {
    ty.onPageNotFound((res) => {
      console.log('Page not found', res.url);
      ty.redirectTo({ url: '/pages/home/index' });
    });
  },
});
```
