#Handle passed to page routes only updates on full page refresh

1 messages · Page 1 of 1 (latest)

chrome wind
#

When doing the following, the handle prop does not update for BlogPage each time a new navigation happens unless a full page refresh occurs. I can confirm this by console logging the value of the handle prop inside of an effect. This means when visiting a different page on the same route, like /blog/hello first and /blog/yo second via a Link element (without full page refresh), it will still display the /blog/hello page even when the URL changes - it does not update the information because the handle doesn't change meaning there are no cascading changes.

Looks like this:

#[nest("/blog")]
            #[route("/:handle")]
            BlogPage { handle: String },

How can it update whenever navigation happens without full page refresh? Thanks.

#

Maybe a workaround is wrapping Link elements but it seems too hacky

keen oak
#

What does your BlogPage component look like?

#

It will rerun when handle changes, but it won't be recreated

#

You may need to change the component (not the enum) to accept ReadOnlySignal<String> to make it reactive

chrome wind
#

I'll test it out

chrome wind
#

Still doesn't work for some reason

#

Here is a snippet:

#[component]
pub fn BlogPage(handle: ReadOnlySignal<String>) -> Element {

    use_effect(move || {
        let current_handle = handle();
        println!("current handle: {}", current_handle.clone());
    });

    ...
}

The effect doesn't run even when the signal is used inside

#
#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
enum Route {
    #[layout(HeaderFooter)]
        #[route("/")]
        Home {},
        #[nest("/blog")]
            #[route("/:handle")]
            BlogPage { handle: String },
        #[end_nest]
    #[end_layout]

    // 404
    #[route("/:..route")]
    NotFound { route: Vec<String> },
}
chrome wind
#

Still not sure why there is no reactivity in this example

keen oak
#

Do you get any logs from the effect?

#

println won't work in wasm, but tracing::info will