Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions website/docs/concepts/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,21 @@ Your components will re-render when provided values change.

#### Struct components

In order to react on route changes, you can pass a callback closure to the `listen()` method of `AnyHistory`.
In order to react on route changes, you can pass a callback closure to the `add_history_listener()` method of `ctx.link()`.

:::note
The history listener will get unregistered once it is dropped. Make sure to store the handle inside your component state.
:::

```rust ,ignore
fn create(ctx: &Context<Self>) -> Self {
let _listener = ctx.link()
.history()
.unwrap()
.listen(ctx.link().callback(
let listener = ctx.link()
.add_history_listener(ctx.link().callback(
// handle event
));
))
.unwrap();
MyComponent {
_listener
_listener: listener
}
}
```
Expand Down