new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Nuxt · API · all subjects

utilities/abort-navigation

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

abortNavigation utility function signature

abortNavigation is a utility function with the signature: export function abortNavigation (err?: Error | string): false. It prevents navigation from taking place and throws an error if one is set as a parameter.

abortNavigation err parameter

The err parameter is optional and accepts either an Error object or a string. It represents an optional error to be thrown by abortNavigation.

abortNavigation only works in route middleware

abortNavigation is only usable inside a route middleware handler. It cannot be used in other contexts.

abortNavigation example with authorization check

The following example shows how to use abortNavigation in a route middleware to prevent unauthorized access: ```ts export default defineNuxtRouteMiddleware((to, from) => { const user = useState('user') if (!user.value.isAuthorized) { return abortNavigation() } if (to.path !== '/edit-post') { return navigateTo('/edit-post') } }) ```

abortNavigation with string error

abortNavigation can accept a string as the error parameter. Example: ```ts export default defineNuxtRouteMiddleware((to, from) => { const user = useState('user') if (!user.value.isAuthorized) { return abortNavigation('Insufficient permissions.') } }) ```

abortNavigation with Error object

abortNavigation can accept an Error object as the error parameter. Example: ```ts export default defineNuxtRouteMiddleware((to, from) => { try { /* code that might throw an error */ } catch (err) { return abortNavigation(err) } }) ```

Give your agent this brain