You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/content/1.documentation/5.advanced/2.faq.md
+69
Original file line number
Diff line number
Diff line change
@@ -145,3 +145,72 @@ security:{
145
145
::alert{type="info"}
146
146
ℹ Read more about it [here](https://github.com/Baroshem/nuxt-security/issues/228).
147
147
::
148
+
149
+
## Updating Headers on an especific route
150
+
151
+
Sometimes you may want to override the default headers on an especific route to allow a certain script to be loaded. You can do that by using the `routeRules` option and loading the headers again by setting the navigation to that route to act as `external`:
152
+
153
+
```ts
154
+
routeRules: {
155
+
// The default headers for all routes
156
+
'/**': {
157
+
headers: {
158
+
'Cross-Origin-Embedder-Policy': 'require-corp'
159
+
}
160
+
},
161
+
// The headers for the route you want to override
162
+
'/example': {
163
+
headers: {
164
+
'Cross-Origin-Embedder-Policy': 'unsafe-none'
165
+
}
166
+
},
167
+
},
168
+
```
169
+
170
+
### Using a Middleware
171
+
172
+
You can create a middleware to handle external navigation as follows:
173
+
174
+
```ts
175
+
// middleware/external-navigation.ts
176
+
177
+
exportdefaultdefineNuxtRouteMiddleware((to) => {
178
+
const routesForExternalLinks = ['/example']
179
+
// Add any other routes you want to act as external links
180
+
181
+
if (
182
+
process.client&&
183
+
!useNuxtApp().isHydrating&&
184
+
to.path&&
185
+
routesForExternalLinks.includes(to.path)
186
+
) {
187
+
window.location.href=to.fullPath
188
+
}
189
+
})
190
+
191
+
```
192
+
193
+
To use this middleware, include it in your script:
194
+
195
+
```ts
196
+
// example.vue
197
+
198
+
<scriptlang="ts"setup>
199
+
definePageMeta({
200
+
middleware: ['external-navigation']
201
+
})
202
+
</script>
203
+
```
204
+
### Using NuxtLink
205
+
206
+
Alternatively, you can use the `external` attribute on `NuxtLink` to set the navigation to external:
0 commit comments