@@ -38,7 +38,7 @@ data MyRoute
3838 = PostIndex
3939 | Post PostId
4040 | PostEdit PostId
41- | PostBrowse String String
41+ | PostBrowse Int String
4242```
4343
4444By using a data type, we can use ` case ` analysis to guarantee that we've
@@ -111,7 +111,7 @@ And now finally, we need to extract multiple segments for `PostBrowse`.
111111``` purescript
112112postBrowse :: Match MyRoute
113113postBrowse =
114- PostBrowse <$> (lit "posts" *> str ) <*> str
114+ PostBrowse <$> (lit "posts" *> lit "browse" *> int ) <*> str
115115```
116116
117117The ` <*> ` combinator has arrows on both sides because we want both values.
@@ -150,7 +150,7 @@ myRoute = oneOf
150150 [ PostIndex <$ lit "posts"
151151 , Post <$> (lit "posts" *> int)
152152 , PostEdit <$> (lit "posts" *> int) <* lit "edit"
153- , PostBrowse <$> (lit "posts" *> str ) <*> str
153+ , PostBrowse <$> (lit "posts" *> lit "browse" *> int ) <*> str
154154 ]
155155```
156156
@@ -166,7 +166,7 @@ myRoute =
166166 [ pure PostIndex
167167 , Post <$> int
168168 , PostEdit <$> int <* lit "edit"
169- , PostBrowse <$> str <*> str
169+ , PostBrowse <$> (lit "browse" *> int) <*> str
170170 ]
171171```
172172
@@ -185,7 +185,7 @@ myRoute =
185185 [ PostIndex <$ end
186186 , Post <$> int <* end
187187 , PostEdit <$> int <* lit "edit" <* end
188- , PostBrowse <$> str <*> str <* end
188+ , PostBrowse <$> (lit "browse" *> int) <*> str <* end
189189 ]
190190```
191191
@@ -199,7 +199,7 @@ myRoute =
199199 lit "posts" *> oneOf
200200 [ PostEdit <$> int <* lit "edit"
201201 , Post <$> int
202- , PostBrowse <$> str <*> str
202+ , PostBrowse <$> (lit "browse" *> int) <*> str
203203 , pure PostIndex
204204 ] <* end
205205```
@@ -217,7 +217,7 @@ myRoute =
217217 root *> lit "posts" *> oneOf
218218 [ PostEdit <$> int <* lit "edit"
219219 , Post <$> int
220- , PostBrowse <$> str <*> str
220+ , PostBrowse <$> (lit "browse" *> int) <*> str
221221 , pure PostIndex
222222 ] <* end
223223```
@@ -234,14 +234,17 @@ matchMyRoute = match myRoute
234234test1 = matchMyRoute "/posts"
235235test2 = matchMyRoute "/posts/12"
236236test3 = matchMyRoute "/posts/12/edit"
237+ test3 = matchMyRoute "/posts/browse/2004/June"
237238test4 = matchMyRoute "/psots/bad"
238239```
239240
240241## Routing events with ` Routing.Hash `
241242
242243Now that we have a parser, we'll want to respond to events and fire a
243244callback like in our original example. ` purescript-routing ` supports
244- hash-based routing via ` Routing.Hash ` .
245+ hash-based routing via ` Routing.Hash ` . Hash-based routing uses anchors
246+ (` # ` or "hash" character) to specify the routes.
247+ For example: ` www.example.com/#posts/12/edit ` .
245248
246249``` purescript
247250import Routing.Hash (matches)
@@ -285,6 +288,9 @@ Alternatively, we could explicitly add a `NotFound` constructor to `MyRoute`.
285288
286289## Routing events with ` Routing.PushState `
287290
291+ PushState-based routing * avoids* the use of anchors (` # ` ) to specify the routes.
292+ For example: ` www.example.com/posts/12/edit ` .
293+
288294Routing with ` Routing.PushState ` is similar to hash-based routing except that
289295we must first create an interface. Browsers don't handle location events
290296directly, so the interface needs to do some bookkeeping of it's own for
0 commit comments