Skip to content

Commit 6d5b4e8

Browse files
chore(prettier): fix unformatted files 🤖 ✨ (#5145)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 65eb8c2 commit 6d5b4e8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

‎packages/sanity/src/router/README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Define the routes for your application and how they should map to application st
1414
```js
1515
import {route} from 'sanity/router'
1616

17-
const router = route.create('/', [route.create('/products/:productId'), route.create('/users/:userId'), route('/:page')])
17+
const router = route.create('/', [
18+
route.create('/products/:productId'),
19+
route.create('/users/:userId'),
20+
route('/:page'),
21+
])
1822

1923
router.encode({})
2024
// => '/'
@@ -81,7 +85,7 @@ function render(location) {
8185
>
8286
<App />
8387
</RouterProvider>,
84-
document.getElementById('container')
88+
document.getElementById('container'),
8589
)
8690
}
8791
history.listen(() => render(document.location))
@@ -135,7 +139,6 @@ const router = route('/', route('/:page'))
135139

136140
Now, `/about` would resolve to the state `{page: 'about'}` which unambiguously can map back to `/page`, and an empty state can map to `/`. To figure out if you are on the index page, you can check for `state.page == null`, (and set the state.page to null to navigate back to the index)
137141

138-
139142
## Search params
140143

141144
URL search parameters will be decoded and made available on the special `_searchParams` key of the router state. This is which is an array of `[key: string, value: string]` tuples, similar to what you'd get from `URLSearchParams.entries()`.
@@ -153,7 +156,9 @@ const router = useRouter()
153156

154157
console.log(router.state)
155158
```
159+
156160
Will log
161+
157162
```ts
158163
{
159164
someParam: 'something',
@@ -168,15 +173,19 @@ const router = useRouter()
168173

169174
router.navigate({
170175
someParam: 'something',
171-
_searchParams: [['foo', 'bar'], ['bar', 'baz']]
176+
_searchParams: [
177+
['foo', 'bar'],
178+
['bar', 'baz'],
179+
],
172180
})
173181
```
182+
174183
Will navigate to:
184+
175185
```
176186
/path/to/something?foo=bar&bar=baz
177187
```
178188

179-
180189
### Transforming path parameters
181190

182191
Query parameters doesn't work too well with router scopes as they operate in a global namespace. A possible workaround is to "fake" query params in a path segment using transforms:
@@ -205,7 +214,7 @@ const router = route(
205214
},
206215
},
207216
},
208-
route('/other/:page')
217+
route('/other/:page'),
209218
)
210219
```
211220

0 commit comments

Comments
 (0)