# Context
export default ({ app, to, from, redirect }) => {
if (to.path === '/protected') {
redirect(from)
} else {
const { visits } = app.$getMiddlewareContext()
app.$updateMiddlewareContext('visits', (visits || 0) + 1)
}
}
# Built-In Properties
The context has the following built-in properties:
# app: VueConstructor
A middleware app object with injected helpers.
# to: Route
The target Route Object being navigated to.
An argument from Navigation Guard
# from: Route
The target Route Object being navigated from.
An argument from Navigation Guard
# redirect: function
A function to redirect to any route. Accepts same arguments as the next
function in a Navigation Guard but unlike a navigation guard, it's not required to be called in each middleware in order to resolve it.
# Adding custom properties
In the above example, we appearently add a property visits
to the middleware context. Goto Helper Functions for more.