Skip to content

Commit

Permalink
fix: pathname access if to prop is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
oedotme committed Mar 2, 2023
1 parent c922b59 commit d2df8cb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugins/react-router/src/client/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export const components = <Path extends string, Params extends Record<string, an

return {
Link: <P extends To>({ to, params, ...props }: PropsWithParams<P>) => {
const path = typeof to === 'string' ? to : String(to.pathname)
const path = typeof to === 'string' ? to : to?.pathname || ''
return <Link {...props} to={params ? generatePath(path, params || {}) : to} />
},
Navigate: <P extends To>({ to, params, ...props }: PropsWithParams<P>) => {
const path = typeof to === 'string' ? to : String(to.pathname)
const path = typeof to === 'string' ? to : to?.pathname || ''
return <Navigate {...props} to={params ? generatePath(path, params || {}) : to} />
},
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/react-router/src/client/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const hooks = <Path extends string, Params extends Record<string, any>>()
const navigate = useNavigate()
return <P extends To | number>(to: P, ...[options]: NavigateOptionsWithParams<P>) => {
if (typeof to === 'number') return navigate(to)
const path = typeof to === 'string' ? to : String(to.pathname)
const path = typeof to === 'string' ? to : to?.pathname || ''
navigate(options?.params ? generatePath(path, options.params || {}) : to, options)
}
},
Expand Down

0 comments on commit d2df8cb

Please sign in to comment.