How to have a default layout for all routes?
I am using
@solidjs/router
and I want to have a default layout to have a default background color. How do I do that?23 Replies
Code:
In my project I have index.jsx like this:
Then in App.jsx
this simply works. if you need a more robust approach, see nested routes https://github.com/solidjs/solid-router#nested-routes
ok
Thank you so much! ❤️
Robust? How is using nested route better? Can you give an example? I just cannot seem to get them to work
This is what I tried:
For some reason, hot reload does not work with this approach properly, you have to manually refresh to see changes
say if some routes are public and some private like auth
This does not work at all ^
It only works for the /login route (shows bg-sky-500 with h-screen)
But not for the
/
routenested routes need a leaf child route to render
a route with empty path would do
for top level site layout i'd go with what @Grahf posted, then use nested routes for auth etc
But hot reload does not work with @Grahf's solution for some reason
doe hmr work in other places?
If I remove the top-level layout, it works fine
The page is not reloaded automatically
hmm, could you move the div out the Router component?
Nope, still does not work
I have switched so many libraries and frameworks because of this issue, Svelte seems to do it perfectly, but I hate few things about it, I would appreciate it if someone can help me
i'll try to repro it locally
fyi hmr for context is still wip i think
Tysm!
Please mention me if you find anything
@pronoob0 seems to be working for me, what's your setup exactly
I am on a mac and I used degit typescript template (manually installed tailwind)
hmm, on a mac as well, and took the same step as and still working fine for me, i don't mind a couple refresh though so our expectations might differ
the only thing that stands out to me is duplicate mounting on
index.tsx
even though @refresh reload
pragma exists
https://codesandbox.io/p/github/mdynnl/solid-tsI am not importing tailwind.css file, is that a problem?
I am just using the @tailwind directives instead
and importing the index.css file
Also, I am directly passing the router to render(), I don't think that's a problem:
I have to manually refresh the browser to see changes for top-level layout, that's the only problem I am having right now
I am just gonna give up on SolidJS for now, unfortunately
What do you recommend as an alternative?
I am thinking of Preact or something
not really sure but
render()
needs to be a separate file as it's necessary to reload the whole pageIf that's the reason why it wasn't working, that would be the stupidest thing the docs re ommend
probably because it was written long before hmr is implemented and hasn't updated ever since
It worked! Thank you so much for saving so much of my time!