Skip to content
Discussion options

You must be logged in to vote

use_navigate returns impl Fn(&str, NavigateOptions) + Clone, so if you want to store it somewhere you can store it as a Box<dyn Fn(&str, NavigateOptions)> (or Arc, etc.). Normal Rust stuff.

#[component]
pub fn App() -> impl IntoView {
    view! {
        <Router>
            <Routes fallback=|| "Not found.">
                <Route path=() view=Something/>
            </Routes>
        </Router>
    }
}

struct StoredNavigateFn {
    navigate: Box<dyn Fn(&str, NavigateOptions)>,
}

#[component]
pub fn Something() -> impl IntoView {
    let stored = StoredNavigateFn {
        navigate: Box::new(use_navigate()),
    };
    view! {
        <button on:click=move |_| {
            (stored.navigate

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dxur
Comment options

Answer selected by dxur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants