diff --git a/nx-dev/data-access-documents/src/lib/documents.api.ts b/nx-dev/data-access-documents/src/lib/documents.api.ts index f22979a157..9e47181d1d 100644 --- a/nx-dev/data-access-documents/src/lib/documents.api.ts +++ b/nx-dev/data-access-documents/src/lib/documents.api.ts @@ -50,7 +50,7 @@ export class DocumentsApi { * Generate the content of a "Category" or "Index" page, listing all its direct items. * @param path */ - getDocumentIndex(path: string[]): DocumentData { + getDocumentIndex(path: string[]): DocumentData | null { let items = this.documents?.itemList; let found: DocumentMetadata | null = null; let itemPathToValidate: string[] = []; @@ -62,11 +62,14 @@ export class DocumentsApi { items = found.itemList; } } + // If the ids have found the item, check that the segment correspond to the id tree if (found && path.join('/') !== itemPathToValidate.join('/')) { found = null; } + if (!found) return null; + const cardListItems = items?.map((i) => ({ name: i.name, path: i.path ?? '/' + path.concat(i.id).join('/'), diff --git a/nx-dev/nx-dev/pages/[...segments].tsx b/nx-dev/nx-dev/pages/[...segments].tsx index 72a746cde2..765d86761a 100644 --- a/nx-dev/nx-dev/pages/[...segments].tsx +++ b/nx-dev/nx-dev/pages/[...segments].tsx @@ -215,7 +215,7 @@ export const getStaticProps: GetStaticProps = async ({ }; } - let document: DocumentData | undefined; + let document: DocumentData | null = null; try { document = documentsApi.getDocument(params.segments); } catch (e) { @@ -226,6 +226,7 @@ export const getStaticProps: GetStaticProps = async ({ } catch (e) { // Do nothing } + if (document) { return { props: {