reflex
reflex copied to clipboard
Is there an on_load event handler for dynamic routes?
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 callPostState.init()
to initialize the vars in the state. - When we move to
/posts/2
, we similarly callPostState.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?