Skip to content

Commit 9ea9f0d

Browse files
committed
docs: Add usage of subscribe()
1 parent e85de4c commit 9ea9f0d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ routerModel.push('/user');
4545
routerModel.goBack();
4646
```
4747

48+
## Listeners
49+
50+
```typescript
51+
import { Model } from '@redux-model/web';
52+
import { routerModel } from '@redux-model/web-router';
53+
54+
class TestModel extends Model<Data> {
55+
protected onInit() {
56+
routerModel.subscribe('/user/:id', ({ id }, location, action) => {
57+
console.log(id);
58+
});
59+
60+
const token = routerModel.subscribe('/article/:id/category/:cate', ({ id, cate }, location, action) => {
61+
console.log(id);
62+
console.log(cate);
63+
});
64+
65+
// In some case, you don't want to listen it any more.
66+
routerModel.unsubscribe(token);
67+
}
68+
}
69+
70+
export const testModel = new TestModel();
71+
```
72+
4873
## Data
4974

5075
### In Hooks

0 commit comments

Comments
 (0)