Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router should bind a elements on document. #566

Open
Dav1dde opened this issue Jan 28, 2023 · 2 comments
Open

Router should bind a elements on document. #566

Dav1dde opened this issue Jan 28, 2023 · 2 comments
Labels
A-router Area: router

Comments

@Dav1dde
Copy link
Contributor

Dav1dde commented Jan 28, 2023

A setup like this with having a links in the nav and footer does not work, because the nav and footer are not enclosed in the router:

     view! { cx,
            nav() {
                Nav()
            }
            main(class="max-w-screen-xl px-5 xl:px-0 w-full flex-auto self-center") {
                Router()
            }
            footer() {
                Footer()
            }
        }
    }

The router should bind to the document instead of the enclosed view only or have an option to pass an element selector to use.

@lukechu10
Copy link
Member

Generally I would just recommend hoisting your Router to the top of your App so that everything gets rendered under the Router. Is there a reason why you can't do that?

Personally, I find the current behavior more intuitive since click events only get captured if they are inside a Router.

@lukechu10 lukechu10 added the A-router Area: router label Jan 28, 2023
@Dav1dde
Copy link
Contributor Author

Dav1dde commented Jan 28, 2023

My switch function for the router selects a page based on the route, the page has associated data which needs to be fetched before it can be rendered and displayed. During this downtime the router can already show a loading view etc.

Now technically it would be possible to move my layouting into the router, I prefer the current setup because my router abstraction is technically standalone and contains no application specific layouting/code, which is a nice separation of concernes and still keeps the structure hierarchical layout -> router -> page content. I don't like the alternative of passing Fn into my router which produces the necessary layout for every route change.

While also probably not relevant it reduces the amount of nodes that need to be rendered on a route change.

An alternative solution could also be move the click event binding code to a separate component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-router Area: router
Projects
None yet
Development

No branches or pull requests

2 participants