Skip to content

Commit

Permalink
fix(navigator-integration): fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
heyqbnk committed Mar 13, 2024
1 parent 996dd21 commit 93a86b9
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions packages/react-router-integration/src/useNavigatorIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,25 @@ function formatTo(to: To): string {
* @param nav - Mini Apps navigator.
*/
export function useNavigatorIntegration(nav: HashNavigator): [Location, Navigator] {
const {
pathname,
hash,
search,
go,
push,
replace,
} = nav;

// Creates location based on the Mini Apps navigator.
const createLocation = useCallback(() => ({
state: null,
key: '',
pathname,
hash,
search,
}), [pathname, hash, search]);
pathname: nav.pathname,
hash: nav.hash,
search: nav.search,
}), [nav]);

const [location, setLocation] = useState(createLocation);

// Create Navigator appropriate to the react-router-dom package.
const navigator = useMemo<Navigator>(() => ({
go: go.bind(nav),
push: push.bind(nav),
replace: replace.bind(nav),
go: nav.go.bind(nav),
push: nav.push.bind(nav),
replace: nav.replace.bind(nav),
createHref: (to) => `#${formatTo(to)}`,
encodeLocation: (to) => new URL(formatTo(to), 'http://localhost'),
}), [go, push, replace, nav]);
}), [nav]);

// When Mini Apps navigator changes its location, we should actualize the reactive values.
useEffect(() => {
Expand Down

0 comments on commit 93a86b9

Please sign in to comment.