next#GetStaticPathsResult TypeScript Examples
The following examples show how to use
next#GetStaticPathsResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.tsx From apps with GNU Affero General Public License v3.0 | 5 votes |
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
return { paths: [], fallback: true };
}
Example #2
Source File: [value].tsx From apps with GNU Affero General Public License v3.0 | 5 votes |
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
return { paths: [], fallback: true };
}
Example #3
Source File: [id].tsx From apps with GNU Affero General Public License v3.0 | 5 votes |
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
return { paths: [], fallback: true };
}
Example #4
Source File: [source].tsx From apps with GNU Affero General Public License v3.0 | 5 votes |
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
return { paths: [], fallback: true };
}
Example #5
Source File: [tag].tsx From apps with GNU Affero General Public License v3.0 | 5 votes |
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
return { paths: [], fallback: true };
}
Example #6
Source File: [...slug].tsx From bedrock-dot-dev with GNU General Public License v3.0 | 5 votes |
getStaticPaths: GetStaticPaths = async ({ locales }) => {
let paths: GetStaticPathsResult['paths'] = []
for (let localeVal of locales || []) {
const locale = getLocale(localeVal)
const nextLocaleParam = locale !== Locale.English ? { locale } : {}
const bedrockVersions = await allFilesList(locale)
const tags = await getTags(locale)
const stableVersionParts = getVersionParts(tags[Tags.Stable][1])
const [ , stableMajor, stableMinor ] = stableVersionParts
for (let [ major, minor, files ] of bedrockVersionsInOrder(bedrockVersions)) {
for (let file of files) {
file = encodeURI(file)
const version = [ major, minor ]
const versionParts = getVersionParts(minor)
const [ , verMajor, verMinor ] = versionParts
let shouldPreload = false
if (verMajor >= stableMajor) {
if (verMajor === stableMajor) {
// generate if the minor is more than that of the stable
shouldPreload = verMinor >= stableMinor
} else {
// generate if of a greater version than stable (ex. 1.17 and stable is 1.16)
shouldPreload = true
}
}
// handle stable and beta routes
if (areVersionsEqual(version, tags[Tags.Stable])) {
paths.push({ params: {slug: ['stable', file]}, ...nextLocaleParam })
shouldPreload = true
} else if (areVersionsEqual(version, tags[Tags.Beta])) {
paths.push({ params: {slug: ['beta', file]}, ...nextLocaleParam })
shouldPreload = true
}
if (shouldPreload) {
paths.push({ params: {slug: [major, minor, file]}, ...nextLocaleParam })
}
}
}
}
return { paths, fallback: 'blocking' }
}
Example #7
Source File: nextHelpers.ts From po8klasie with GNU General Public License v3.0 | 5 votes |
getStaticPathsPerProject = async (): Promise<GetStaticPathsResult> => {
const { projectsIDs } = await import('./index');
const paths = projectsIDs.map((projectID) => ({
params: { projectID },
}));
return { paths, fallback: false };
}
Example #8
Source File: Post.spec.tsx From space-traveling with MIT License | 4 votes |
describe('Post', () => {
beforeAll(() => {
mockedUseRouter.mockReturnValue({
isFallback: false,
});
mockedPrismic.mockReturnValue({
getByUID: () => {
return Promise.resolve(mockedGetByUIDReturn);
},
query: () => {
return Promise.resolve(mockedQueryReturn);
},
});
});
it('should be able to return prismic posts documents paths using getStaticPaths', async () => {
const getStaticPathsReturn = [
{
params: {
slug: 'como-utilizar-hooks',
},
},
{
params: {
slug: 'criando-um-app-cra-do-zero',
},
},
];
const getStaticPathsContext: GetStaticPathsContext = {};
const response = (await getStaticPaths(
getStaticPathsContext
)) as GetStaticPathsResult;
expect(response.paths).toEqual(getStaticPathsReturn);
});
it('should be able to return prismic post document using getStaticProps', async () => {
const routeParam = parse('como-utilizar-hooks');
const postReturn = mockedGetByUIDReturn;
const getStaticPropsContext: GetStaticPropsContext<ParsedUrlQuery> = {
params: routeParam,
};
const response = (await getStaticProps(
getStaticPropsContext
)) as GetStaticPropsResult;
expect(response.props.post).toEqual(postReturn);
});
it('should be able to render post document info', () => {
const postProps = mockedGetByUIDReturn;
render(<Post post={postProps} />);
screen.getByText('Como utilizar Hooks');
screen.getByText('25 mar 2021');
screen.getByText('Joseph Oliveira');
screen.getByText('4 min');
screen.getByText('Proin et varius');
screen.getByText(/Nullam dolor sapien/);
screen.getByText('Cras laoreet mi');
screen.getByText(/Ut varius quis velit sed cursus/);
});
it('should be able to render loading message if fallback', () => {
mockedUseRouter.mockReturnValueOnce({
isFallback: true,
});
const postProps = mockedGetByUIDReturn;
render(<Post post={postProps} />);
screen.getByText('Carregando...');
});
it('should be able to render Header component', () => {
const postProps = mockedGetByUIDReturn;
render(<Post post={postProps} />);
screen.getByAltText('logo');
});
});