'nuxt page middleware does not run on server first when pressing browser's back button
I have a page middleware where I am fetching some data for a feature flag. The middleware / flag works fine when navigating to the page within the application, but if I navigate back to it using the browser's back button, it errors out because ssrContext is not defined, presumably because the middleware is running on the client first and not the server. Is there any way to get the server middleware to run first upon navigation using the browser's back / forward buttons? Thanks!
<template>
<h1>Page I want to render</h1>
</template>
<script>
export default {
async middleware({ redirect, ssrContext }) {
// ssrContext is undefined when navigating with browser's back button, causes and error
// otherwis works perfectly whilst nabivigating with the app's nuxt-links
const featurEnabled = await ssrContext.$featureFlagClient?.getValueAsync(
"featureEnabled",
false
)
if (!featureEnabled) {
redirect(`/`)
}
},
}
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
