diff --git a/src/library-authoring/LibraryLayout.tsx b/src/library-authoring/LibraryLayout.tsx
index 728d31cab..add33f95a 100644
--- a/src/library-authoring/LibraryLayout.tsx
+++ b/src/library-authoring/LibraryLayout.tsx
@@ -2,10 +2,12 @@ import { useCallback } from 'react';
import {
Route,
Routes,
+ useMatch,
useParams,
+ type PathMatch,
} from 'react-router-dom';
-import { ROUTES } from './routes';
+import { BASE_ROUTE, ROUTES } from './routes';
import LibraryAuthoringPage from './LibraryAuthoringPage';
import { LibraryProvider } from './common/context/LibraryContext';
import { SidebarProvider } from './common/context/SidebarContext';
@@ -22,8 +24,15 @@ const LibraryLayout = () => {
throw new Error('Error: route is missing libraryId.');
}
+ // The top-level route is `${BASE_ROUTE}/*`, so match will always be non-null.
+ const match = useMatch(`${BASE_ROUTE}${ROUTES.COLLECTION}`) as PathMatch<'libraryId' | 'collectionId'> | null;
+ const collectionId = match?.params.collectionId;
+
const context = useCallback((childPage) => (
{
>
- ), []);
+ ), [collectionId]);
return (