Middleware is not running when page refresh (F5) in mode: 'universal'

sudhir600
10
sudhir600
commented 10 months ago

Hi,
In my application, there is one requirement to match certain value on page refresh as well as route change.
While changing routes, middleware is executing but when i refreshing the page (F5), middleware is not executing.
To overcome this issue, what i did is that, i created "check.js" in plugin and added into nuxt.config.js

Here problem is that, plugin is not executing in route change (it work only on refresh).

Middleware - F5 No | in routes YES
Plugin - F5 YES | In routes No

Basically i don't want to write same code in two places. so may anyone guide me that how a common method can execute on both way.

Here is my codes
Nuxt.config.js
module.exports = { mode: 'universal', router: { middleware: ['roles'] // roles have same code which have in check.js }, plugins: [ { src: '~/plugins/check.js'} ] ....

Thanks in Advance.

0
yuanwei92
0
yuanwei92
commented 10 months ago

@sudhir600 I'm not sure whether it's the right way but this is how I work around it. Since middleware only works for client side rendering, I run the logic inside page or layout and save the value to vuex for future checking.

0
Informations
Question โ€ข Unresolved
#c8367 - Created 10 months ago