docs(core): include fallback paths during SSG (#5850)
This commit is contained in:
parent
a6772c4346
commit
d01bac7440
@ -12,9 +12,10 @@ import { documentsApi, menuApi } from '../lib/api';
|
|||||||
import { useStorage } from '../lib/use-storage';
|
import { useStorage } from '../lib/use-storage';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import Head from 'next/head';
|
||||||
|
|
||||||
const versionList = documentsApi.getVersions();
|
const versionList = documentsApi.getVersions();
|
||||||
const defaultVersion = versionList[0];
|
const defaultVersion = versionList.find((v) => v.default);
|
||||||
const defaultFlavor = {
|
const defaultFlavor = {
|
||||||
label: 'React',
|
label: 'React',
|
||||||
value: 'react',
|
value: 'react',
|
||||||
@ -71,6 +72,14 @@ export function DocumentationPage({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{isFallback && (
|
||||||
|
<Head>
|
||||||
|
<link
|
||||||
|
rel="canonical"
|
||||||
|
href={`/${version.id}/${flavor.value}${router.asPath}`}
|
||||||
|
/>
|
||||||
|
</Head>
|
||||||
|
)}
|
||||||
<DocViewer
|
<DocViewer
|
||||||
version={version}
|
version={version}
|
||||||
versionList={versions}
|
versionList={versions}
|
||||||
@ -179,10 +188,30 @@ export async function getStaticProps({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
|
const allPaths = versionList.flatMap((v) => {
|
||||||
|
const paths = documentsApi.getStaticDocumentPaths(v.id);
|
||||||
|
|
||||||
|
// Use `/latest/react` as the default path if version and flavor not provided.
|
||||||
|
// Make sure to set `isFallback: true` on the static props of these paths so
|
||||||
|
if (v.id === defaultVersion.id) {
|
||||||
|
paths.concat(
|
||||||
|
paths
|
||||||
|
.filter((path) => path.params.segments[1] === defaultFlavor.value)
|
||||||
|
.map((path) => ({
|
||||||
|
...path,
|
||||||
|
params: {
|
||||||
|
...path.params,
|
||||||
|
segments: path.params.segments.slice(2),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
paths: versionList.flatMap((v) =>
|
paths: allPaths,
|
||||||
documentsApi.getStaticDocumentPaths(v.id)
|
|
||||||
),
|
|
||||||
fallback: 'blocking',
|
fallback: 'blocking',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user