forked from Sage-Bionetworks/synapse-web-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix NF portal OrganizationDetailsPage to pass searchParams along since there are multiple lookup keys - add hook to dynamically set document.title
- Loading branch information
Showing
3 changed files
with
34 additions
and
4 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
27 changes: 27 additions & 0 deletions
27
apps/synapse-portal-framework/src/utils/useDocumentTitleFromRoutes.ts
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,27 @@ | ||
import { useEffect } from 'react' | ||
import { useMatches } from 'react-router-dom' | ||
|
||
/** | ||
* Uses the current routes to set the document title. The title will only be set when routes change, so if placed high | ||
* in the React tree, descendant components (e.g. Details pages) can implement their own logic to override the behavior | ||
* as long as they rerun when the routes change. | ||
*/ | ||
export function useDocumentTitleFromRoutes() { | ||
const matches = useMatches() | ||
|
||
useEffect(() => { | ||
// As a heuristic, we get the last path string of the most specific current route. | ||
|
||
// To improve this, we could put custom data in the route handle returned by useMatches: | ||
// https://reactrouter.com/en/main/hooks/use-matches#usematches | ||
|
||
const portalTitle = import.meta.env.VITE_PORTAL_NAME | ||
const routeTitle = matches.at(-1)?.pathname.split('/').at(-1) | ||
if (routeTitle) { | ||
document.title = `${portalTitle} - ${routeTitle}` | ||
} else { | ||
// Set a default title | ||
document.title = portalTitle | ||
} | ||
}, [matches]) | ||
} |