Flowbite not working when using nuxtlink
Hi, I am using tailwind with flowbite in my nuxt project. I installed flowbite using the instructions on their site, if I use the traditional way of loading the page everything works as it should. But when I switch the page using nuxtlink, the flowbite components that are new on the page don't work. Please help.
My app.vue:
21 Replies
I use flowbite from their site, via the html data parameter. Is that right?
maybe I should init remove this script from the app and put it in each component separately?
or each page
Idk but maybe you could watch the route then initFlowbite when it change?
I never used flowbite tbh
hey @Rush did you find a better way than putting init on each componant / page ? Thanks !
Hi, I stopped using init completely and instead initialized each component manually, they say it's better for single page applications
Ok thanks.
I found this fyi : https://stackoverflow.com/questions/77693870/how-to-instantiate-initflowbite-globally-instead-of-per-page-component-in-nuxt
and its working for me
if I remember correctly, I also tried it and left it because, for example, the navbar remained open after changing the page, so I then closed it manually after changing the page
Oh ok. So probably depending on how we are using the app
So currently if you need modal on a component you import it, a tooltip on an other, you import it too inside…
can you confirm @Rush ? thanks
I didn't understand you, how to import inside?
if you want to close them after switching routes, you have to manually initialize them and add that logic there
e.g. add a function to nuxtlink in that modal component that will hide it
I mean in your current workflow you are using
onMounted(() => {
initTooltips();
})
On a component which uses tooltip
onMounted(() => {
initModals();
initDropdowns();
})
In a component which uses modals + dropdowns… etc
If I understand well.
Regarding the issue reported by people like you : when switching page, the js didn’t work anymore
no
You said « initialize each component manually »
By this I guess that you are using code like the one I provided
this is how i do it
this is manually
Ohh I am not here yet
I was more on the issue where the JS is broken by navigating on the app without hard refresh
Which is fixed by onMounted everywhere OR the stack overflow I put
You see ?
Or… doing what to do is also a way to not have the JS broken
I see, that solves the "broken"
but flowbite is designed so that after changing the page everything is loaded again, nuxt doesn't do that, you have to add the logic for it yourself
this is what i am calling on nuxtlink click
Yep but flowbite has a documentation page for nuxt install which don’t cover that. Thats why there is few people like me asking
I had the same
But now I have a scenario where I need to close a modal from a js function. So I will initialize the modal in the same official way as you
Until now never had the need to initialize a thing.
Every tooltip, modal… work out the box with just html
thats because of the nuxt
for example in pure html or php project you dont have to do that
because its not single page app
Yep here its because the dom is re-written