mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-12 17:13:56 +00:00
82 lines
2.1 KiB
Markdown
82 lines
2.1 KiB
Markdown
# Pages
|
|
|
|
Nuxt will automatically integrate [Vue Router](https://next.router.vuejs.org/) and map `pages/` directory into the routes of your application.
|
|
|
|
## Dynamic Routes
|
|
|
|
If you place anything within square brackets, it will be turned into a [dynamic route](https://next.router.vuejs.org/guide/essentials/dynamic-matching.html) parameter. You can mix and match multiple parameters and even non-dynamic text within a file name or directory.
|
|
|
|
### Example
|
|
|
|
```bash
|
|
-| pages/
|
|
---| index.vue
|
|
---| users-[group]/
|
|
-----| [userid].vue
|
|
```
|
|
|
|
Given the example above, you can access group/userid within your component via the `$route` object:
|
|
|
|
```vue
|
|
<template>
|
|
{{ $route.params.group }}
|
|
{{ $route.params.id }}
|
|
</template>
|
|
```
|
|
|
|
## Layouts
|
|
|
|
Nuxt provides a customizable layouts framework you can use throughout your application, ideal for extracting common UI or code patterns into reusable layout components.
|
|
|
|
Page layouts are placed in the `layouts/` directory and will be automatically loaded via asynchronous import when used. If you create a `layouts/default.vue` this will be used for all pages in your app. Other layouts are used by setting a `layout` property as part of your component options.
|
|
|
|
If you have only single layout for application, you can alternatively use (app entry)[/app].
|
|
|
|
### Example: a custom layout
|
|
|
|
```bash
|
|
-| layouts/
|
|
---| custom.vue
|
|
```
|
|
|
|
In your layout files, you'll need to use `<slot />` to define where the page content of your layout will be loaded. For example:
|
|
|
|
```vue
|
|
<template>
|
|
<div>
|
|
Some shared layout content:
|
|
<slot />
|
|
</div>
|
|
</template>
|
|
```
|
|
|
|
Given the example above, you can use a custom layout like this:
|
|
|
|
```vue
|
|
<script>
|
|
export default {
|
|
layout: "custom",
|
|
};
|
|
</script>
|
|
```
|
|
|
|
### Example: using with slots
|
|
|
|
You can also take full control (for example, with slots) by using the `<NuxtLayout>` component (which is globally available throughout your application) and set `layout: false` in your component options.
|
|
|
|
```vue
|
|
<template>
|
|
<NuxtLayout name="custom">
|
|
<template #header> Some header template content. </template>
|
|
|
|
The rest of the page
|
|
</NuxtLayout>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
layout: false,
|
|
};
|
|
</script>
|
|
```
|