mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
docs(pages): add example of limiting scanned routes (#19181)
This commit is contained in:
parent
c4eb4b784c
commit
b1fd5200f5
@ -423,6 +423,35 @@ export default defineNuxtConfig({
|
||||
})
|
||||
```
|
||||
|
||||
## Modifying or Removing Scanned Pages
|
||||
|
||||
Nuxt will create a route for all files ending with one of the `extensions` configured in `nuxt.config`. (By default these are `.js`, `.jsx`, `.mjs`, `.ts`, `.tsx` and `.vue`.)
|
||||
|
||||
You can change or remove pages from the scanned routes with the `pages:extend` nuxt hook. For example, to prevent creating routes for any `.ts` files:
|
||||
|
||||
```ts [nuxt.config.ts]
|
||||
export default defineNuxtConfig({
|
||||
hooks: {
|
||||
'pages:extend' (pages) {
|
||||
function removePagesMatching (pattern: RegExp, pages: NuxtPage[] = []) {
|
||||
const pagesToRemove = []
|
||||
for (const page of pages) {
|
||||
if (pattern.test(page.file)) {
|
||||
pagesToRemove.push(page)
|
||||
} else {
|
||||
removePagesMatching(pattern, page.children)
|
||||
}
|
||||
}
|
||||
for (const page of pagesToRemove) {
|
||||
pages.splice(pages.indexOf(page), 1)
|
||||
}
|
||||
}
|
||||
removePagesMatching(/\.ts$/, pages)
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Programmatic Navigation
|
||||
|
||||
Nuxt 3 allows programmatic navigation through the `navigateTo()` utility method. Using this utility method, you will be able to programmatically navigate the user in your app. This is great for taking input from the user and navigating them dynamically throughout your application. In this example, we have a simple method called `navigate()` that gets called when the user submits a search form.
|
||||
|
Loading…
Reference in New Issue
Block a user