File tree 1 file changed +59
-0
lines changed
1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,65 @@ import AsyncRoute from 'preact-async-route';
73
73
< / Router>
74
74
```
75
75
76
+ ### Active Matching & Links
77
+
78
+ ` preact-router ` includes an add-on module called ` match ` that lets you wire your components up to Router changes.
79
+
80
+ Here's a demo of ` <Match> ` , which invokes the function you pass it (as its only child) in response to any routing:
81
+
82
+ ``` js
83
+ import Router from ' preact-router' ;
84
+ import Match from ' preact-router/match' ;
85
+
86
+ render (
87
+ < div>
88
+ < Match path= " /" >
89
+ { ({ matches, path, url }) => (
90
+ < pre> {url}< / pre>
91
+ ) }
92
+ < / Match>
93
+ < Router>
94
+ < div default> demo fallback route< / div>
95
+ < / Router>
96
+ < / div>
97
+ )
98
+
99
+ // another example: render only if at a given URL:
100
+
101
+ render (
102
+ < div>
103
+ < Match path= " /" >
104
+ { ({ matches }) => matches && (
105
+ < h1> You are Home! < / h1>
106
+ ) }
107
+ < / Match>
108
+ < Router / >
109
+ < / div>
110
+ )
111
+ ```
112
+
113
+ ` <Link> ` is just a normal link, but it automatically adds and removes an "active" classname to itself based on whether it matches the current URL.
114
+
115
+ ``` js
116
+ import { Router } from ' preact-router' ;
117
+ import { Link } from ' preact-router/match' ;
118
+
119
+ render (
120
+ < div>
121
+ < nav>
122
+ < Link activeClassName= " active" href= " /" > Home< / Link>
123
+ < Link activeClassName= " active" href= " /foo" > Foo< / Link>
124
+ < Link activeClassName= " active" href= " /bar" > Bar< / Link>
125
+ < / nav>
126
+ < Router>
127
+ < div default>
128
+ this is a demo route that always matches
129
+ < / div>
130
+ < / Router>
131
+ < / div>
132
+ )
133
+ ```
134
+
76
135
---
77
136
78
137
You can’t perform that action at this time.
0 commit comments