Layout doesn't change when using navigateTo in the nuxt middleware
this is my /auth/login page
this is my auth layout
7 Replies
this is my index page
this is my home layout
this is my require-unauth middleware
this is the require-auth middle ware
when i try to access to /auth/login while i am already logged in it redirect me back to the index page but doesnt change the layout
and gives me this error on console
chunk-2435C5CU.js?v=991d9edc:1513 [Vue warn]: Hydration node mismatch:
rendered on server: <!--[--> (start of fragment)
expected on client: div at <Home ref=Ref< undefined > > at <LayoutLoader key="home" layoutProps= {ref: RefImpl}ref: RefImpldep: undefinedv_isRef: truev_isShallow: false_rawValue: Proxy(Object) {getRouteBaseName: ƒ, resolveRoute: ƒ, localePath: ƒ, localeRoute: ƒ, localeLocation: ƒ, …}_value: Proxy(Object) {getRouteBaseName: ƒ, resolveRoute: ƒ, localePath: ƒ, localeRoute: ƒ, localeLocation: ƒ, …}value: (...)[[Prototype]]: Object[[Prototype]]: Object name="home" > at <NuxtLayoutProvider layoutProps= {ref: RefImpl} key="home" name="home" ... > at <BaseTransition mode="out-in" appear=false persisted=false ... > at <Transition name="layout" mode="out-in" > at <NuxtLayout> at <App key=3 > at <NuxtRoot>
when i inspect i found my self still in auth layout
it only gets fixed when i push the navigateTo with external is true
which doesnt make sense for me
How your App.vue look?
this is my app.vue
@Zeeethany clue ?
hmmm it seems when i force to external with true it works
weired
how can i pause the middleware till the hydration is ended ?
No updates till now
when i sklip the middleware on hydrating using
if(useNuxtApp().isHydrating) return
it no longer now send the request at all
@NT Diesel if your issue is still persisting, it might help to provide to reproduction
@Orbviox sure
I will do it today
no
here u go
https://codesandbox.io/p/github/PT-Mohamed-Hussein/error-reporduction/main?import=true
this is the code sand box
this is the link of the site
https://qwks9x-3000.csb.app/auth/login
when u access to the index directly it works fine
but when u access to the /auth/login and the middle ware redirect u it doesnt change the layout which appear from the background color
the background color of the auth layout is white while of the home is red
when u get redirect the background will still white while it suppose to be red while the text ie the page content is changing
while if i removed the wait or any request from the middleware it will works perfectly fine
issue still presist even when i remove the transition
whole code shown in the sandbox i just posted
its just new nuxt app
issue is coming when i do any thing used async data
like fetch api or timeout
when i removed both it works perfectly
use this link
https://qwks9x-3000.csb.app/auth/login
in the sandbox
its bugged idk why
is it woked ?
i dont know whats wrong with codesandbox
i will sen u the link of the repo
its public
GitHub
GitHub - PT-Mohamed-Hussein/error-reporduction
Contribute to PT-Mohamed-Hussein/error-reporduction development by creating an account on GitHub.
here u go
sry for remention i just updated something in the repo
What if i used pinia presisted state and send to back end the accesstoken from pinia store in the body of request instead of getting it from cookies
And allow the request to be done on the server side
I think this will be good
I will give it a try
I managed tk solve it using pinia presisted stTe
And send the token in the body during ssr