I am trying out kobweb. It looks really great so f...
# kobweb
p
I am trying out kobweb. It looks really great so far. Is it possible to render a navigation menu with access to the router (possible to change route) without being in a @Page context? I can only do this by putting the navigation into each page. I noticed that the whole html re-renders in the browser even if it does not change. Having something like nested routes would be nice.
d
When would the navigation menu be rendered outside of a page?
We are probably a week away from releasing a feature called "Layouts" which may resolve the issue you're facing here with the re-rendering
Basically a restructuring where pages will always recompose, but the template layout they exist in will not
I'm not sure what you mean by "nested routes"
p
Lets say i have this page layout: |Header| |Menu| |Page Content| |Footer| I want to render only the |Page Content| with different content depending on the last url part Example: /home, /settings In react-router you can have child routes: https://reactrouter.com/start/data/routing
d
Then my recommendation for you is to wait a week 🙂
p
Ok 🙂
d
You can grab the snapshot NOW if you want to. And I can link to my own site that I've migrated over.
p
Thanks, I will wait. Still enough other things to discover now.
d
But you can also wait a little bit, like in a day or two I will write docs at least in some internal places I can share.
Awesome 🙂
Pretty good of you to notice this so quickly into experimenting with Kobweb
As for child routes, I should mention that that won't exist in a week
I think the recommendation is just create multiple pages and delegate to a private composable if you want them to share the same logic
You can also use dynamic routes, which maybe that's what you want there?
p
True, I could just make the url a slug and use it with
when
to render the page dynamically.
d
Yeah. There's nothing stopping you from doing that today
I'm still not 100% sure that layouts were the core issue you were having, but I just finished a preview version of the docs today, so I thought I'd share. You can check them out and see if this is what you were asking for or not. https://preview.kobweb.varabyte.com/docs/concepts/foundation/layouts
It will probably be later next week that I'll release this feature, but if you wanted to try it earlier, you could set your Kobweb version to 0.21.2-SNAPSHOT.
p
I tested it and it looks good. 🎆 With Layout’s only the actual page content is rendered. My navigation just updates as expected.
🙌 1
d
Thank you for checking it out! As one of the first few people ever using the feature, please don't hesitate to share any feedback.
p
I think its a nice concept. I do not like strings for class names though, as this is not safe for automatic refactorings 🙂 Will share some more general feedback separately.
Copy code
@Layout(BaseLayout::class)
Would that work?
d
As much as I wish it would, it would not for two reasons. First, annotations can only take compile-time constants, and second, composable methods are functions and don't expose a class
We have a bare bones IntelliJ plugin which we plan to start investing in heavily in the near future to fill out its feature set. That's how we plan to sort out issues of dealing with raw strings.
At least you can know that if you refactor code at the moment, you'll get a bunch of compile errors pointing out the broken layouts
👍 1