Skip to content

Commit 07c4174

Browse files
committed
Update ROUTER.md
1 parent 2e3e42a commit 07c4174

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

extra/ROUTER.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ Routers are not interchangable between routing rule sets.
113113

114114
#### Rendering your Router
115115

116-
Before a `Router` can be created it needs to the base URL, which is the prefix portion of the URL that is the same for all your pages routes.
116+
Before a `Router` can be created it needs to know the base URL, which is the prefix portion of the URL that is the same for all your pages routes.
117117

118-
It needn't be absolute at compile-time, but it needs to be absolute at runtime. `BaseUrl.fromWindowOrigin` will give you the protocol, domain and port at runtime, after which you should append a path if necessary. Example: `BaseUrl.fromWindowOrigin / "my_page"`
118+
It needn't be absolute at compile-time, but it needs to be absolute at runtime. `BaseUrl.fromWindowOrigin` will give you the protocol, domain and port at runtime, after which you should append a path if necessary. Example: `BaseUrl.fromWindowOrigin / "my_page"` instead of using `BaseUrl("http://blah.com/my_page")` or `BaseUrl("http://127.0.0.1:8080/my_page")` directly.
119119

120120
Once you have a your `BaseUrl`, call `<RoutingRules>.router(baseUrl)` to get a standard React component of your router.
121121

@@ -181,6 +181,11 @@ override protected def interceptRender(i: InterceptionR): ReactElement =
181181
`RoutingRules` comes with a built-in (although inactive) URL rewriting rule called `removeTrailingSlashes`.
182182
It can be installed via `register()` and is a good example of how to create dynamic matching rules.
183183

184+
To use it:
185+
```scala
186+
register(removeTrailingSlashes)
187+
```
188+
184189
Its implementation is simple:
185190
```scala
186191
def removeTrailingSlashes: DynamicRoute = {
@@ -191,9 +196,10 @@ def removeTrailingSlashes: DynamicRoute = {
191196

192197
#### Callback: `onRouteChange`
193198
By default, when a new route is activated the window is scrolled to the top.
194-
This behaviour can be removed or customised by providing a callback in your routing rules called `onRouteChange`.
199+
This behaviour can be removed or customised by calling `onRouteChange` in your routing rules and providing it a `Loc => Unit`.
195200

196201
```scala
197202
onRouteChange { loc =>
203+
println(s"Route has changed to: $loc")
198204
...
199-
}
205+
}

0 commit comments

Comments
 (0)