-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update typesafe routing for admin ui (#610)
- Loading branch information
1 parent
43907dc
commit a0a7c7c
Showing
6 changed files
with
250 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Location, useLocation, useParams } from "@remix-run/react"; | ||
import { useMemo } from "react"; | ||
|
||
import { RouteService } from "~/lib/service/routeService"; | ||
|
||
const urlFromLocation = (location: Location) => { | ||
const { pathname, search, hash } = location; | ||
return new URL(window.location.origin + pathname + search + hash); | ||
}; | ||
|
||
export function useUrl() { | ||
const location = useLocation(); | ||
|
||
return useMemo(() => urlFromLocation(location), [location]); | ||
} | ||
|
||
export function useUnknownPathParams() { | ||
const url = useUrl(); | ||
const params = useParams(); | ||
|
||
return useMemo( | ||
() => RouteService.getUnknownRouteInfo(url, params), | ||
[url, params] | ||
); | ||
} |
Oops, something went wrong.