reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Is there an on_load event handler for dynamic routes?

Open heumsi opened this issue 1 year ago β€’ 0 comments

Dynamic routes are very useful and I've been using them well.

However, I would like to have a specific function (event handler) triggered when navigating to a dynamic route. Is there any way to do this?

For example, let's say I defined a dynamic route like this

app.add_page(post, route="/posts/[post_id]", on_load=PostState.init)

When written like this, we expect it to behave like this

  • When we navigate to /posts/1, we can call PostState.init() to initialize the vars in the state.
  • When we move to /posts/2, we similarly call PostState.init() to initialize the vars in State.

However, for now, the on_load event is only called once in the above scenario, i.e. we don't call PostState.init() when we navigate to /posts/2.

I don't think I'm calling the on_load event for every dynamic route.

Is there any way to fix this?

heumsi avatar Feb 27 '23 15:02 heumsi