`router.params.:section` includes search params
I think there is a bug when using `router.params.section` because that includes the searchParams `einleitung?map=11.70689512859718/52.42790930166814/13.766570682486531`. I expect the value to be just `einleitung`
The consequence is, that the `redirectPage` appends the search params multiple times.
Here is some testing log from `router` from `useStore($router)` (first) and `$router.get()` (second):
```json
{
"useStore": {
"params": {
"section": "einleitung?map=11.70689512859718/52.42790930166814/13.766570682486531"
},
"path": "/radnetz/einleitung?map=11.70689512859718%2F52.42790930166814%2F13.766570682486531",
"route": "radnetz",
"search": {
"map": "11.70689512859718/52.42790930166814/13.766570682486531"
}
},
"$routerGet": {
"params": {
"section": "einleitung?map=11.70689512859718/52.42790930166814/13.766570682486531"
},
"path": "/radnetz/einleitung?map=11.70689512859718%2F52.42790930166814%2F13.766570682486531",
"route": "radnetz",
"search": {
"map": "11.70689512859718/52.42790930166814/13.766570682486531"
}
}
}
```
Why does `params.section` hold the search params in this case?
The example at https://github.com/nanostores/router?tab=readme-ov-file#search-query-routing suggest, that the search params should not be part of this.
<details><summary>Details</summary>
This is my router:
```
const $router = createRouter(
{
radnetz: '/radnetz/:section',
},
{
search: true,
},
)
```
And when I use `redirectPage($router, 'radnetz', { section: router.params.section }, { map: mapParam })` the params get appended multiple times like `http://127.0.0.1:4321/radnetz/einleitung%3Fmap%3D11.70689512859718%2F52.42790930166814%2F13.766570682486531%3Fmap%3D11.70689512859718%2F52.417749284715796%2F13.800943192344107%3Fmap%3D11.70689512859718%2F52.40512106127093%2F13.790336696086683?map=11.70689512859718%2F52.39756364765955%2F13.80544478561933` (there is 4x `map` in this string)
</details>
---
An side question is: What is the recommended way to subscribe to a router state? https://github.com/nanostores/router?tab=readme-ov-file#usage hints at using https://github.com/nanostores/nanostores#guide as reference so I used `const router = useStore($router)`. Should I use this or the `get` method from https://github.com/nanostores/router?tab=readme-ov-file#search-query-routing?
关闭于 2024-05-17 1 条评论