Skip to content

Commit

Permalink
Copy queryParams & hash in props route (#153)
Browse files Browse the repository at this point in the history
* Copy queryParams & hash in props route

* Update test
  • Loading branch information
Willy Brauner committed Nov 9, 2023
1 parent f2efc01 commit b9e93be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { isSSR, removeLastCharFromString } from "../core/helpers"

export type TRouteProps = {
params?: TParams
queryParams?: TQueryParams
hash?: string
[x: string]: any
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ export function getRouteFromUrl({
hash,
props: {
params,
queryParams,
hash,
...(route?.props || {}),
},
_fullPath: currentRoutePath,
Expand Down
9 changes: 8 additions & 1 deletion src/tests/core.getRouteFromUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ describe("getRouteFromUrl", () => {
expect(getRoute.path).toBe("/bar/:id")
expect(getRoute.url).toBe("/bar/my-id")
expect(getRoute.name).toBe(`BarPage`)
const routeProps = { params: { id: "my-id" }, color: "blue" }
const routeProps = {
params: { id: "my-id" },
queryParams: {},
hash: null,
color: "blue",
}
expect(getRoute.props).toEqual(routeProps)
// no parent route, so context object need to return same route information
expect(getRoute._context.props).toEqual(routeProps)
Expand Down Expand Up @@ -57,6 +62,8 @@ describe("getRouteFromUrl", () => {
expect(getRoute.props).toEqual({
color: "red",
params: { testParam: "super-param" },
queryParams: {},
hash: null,
})
})

Expand Down

0 comments on commit b9e93be

Please sign in to comment.