Skip to content

Commit

Permalink
chore(prettier): fix unformatted files 🤖 ✨ (#5145)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ecospark[bot] and github-actions[bot] authored Nov 9, 2023
1 parent 65eb8c2 commit 6d5b4e8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/sanity/src/router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ Define the routes for your application and how they should map to application st
```js
import {route} from 'sanity/router'

const router = route.create('/', [route.create('/products/:productId'), route.create('/users/:userId'), route('/:page')])
const router = route.create('/', [
route.create('/products/:productId'),
route.create('/users/:userId'),
route('/:page'),
])

router.encode({})
// => '/'
Expand Down Expand Up @@ -81,7 +85,7 @@ function render(location) {
>
<App />
</RouterProvider>,
document.getElementById('container')
document.getElementById('container'),
)
}
history.listen(() => render(document.location))
Expand Down Expand Up @@ -135,7 +139,6 @@ const router = route('/', route('/:page'))

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)


## Search params

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()`.
Expand All @@ -153,7 +156,9 @@ const router = useRouter()

console.log(router.state)
```

Will log

```ts
{
someParam: 'something',
Expand All @@ -168,15 +173,19 @@ const router = useRouter()

router.navigate({
someParam: 'something',
_searchParams: [['foo', 'bar'], ['bar', 'baz']]
_searchParams: [
['foo', 'bar'],
['bar', 'baz'],
],
})
```

Will navigate to:

```
/path/to/something?foo=bar&bar=baz
```


### Transforming path parameters

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:
Expand Down Expand Up @@ -205,7 +214,7 @@ const router = route(
},
},
},
route('/other/:page')
route('/other/:page'),
)
```

Expand Down

2 comments on commit 6d5b4e8

@vercel
Copy link

@vercel vercel bot commented on 6d5b4e8 Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio-git-next.sanity.build
performance-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 6d5b4e8 Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.