Skip to content

Commit 7e14dc6

Browse files
06180618
andauthored
fix(docs): 404 routing (#2478)
* fix: use getStaticPaths to restrict platform param * fix(docs): remove useCustomRouter * fix(docs): build issue * refactor: add getCustomStaticPath * chore(docs): add comment for getStaticProps * fix(docs): comment syntax * refactor(docs): use preval for getCustomStaticPath * fix(docs): getCustomStaticPath platformsArr * fix(docs): remove figma from unavailable framework nav * fix(docs): use frontmatter to replace preval for supportedFramework * fix(docs): getCustomStaticPath undefined Co-authored-by: 0618 <[email protected]>
1 parent 35dae2a commit 7e14dc6

File tree

88 files changed

+846
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+846
-105
lines changed

docs/next.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,22 @@ module.exports = withNextPluginPreval({
136136
},
137137
/**
138138
* source: a url has one of the folder's names (components, getting-started, guides, theming)
139-
* destination: add '[platform]' to the the beginning
139+
* destination: add '/react/' to the the beginning
140140
*/
141141
{
142142
source:
143143
'/:nav(legacy-components|connected-components|components|getting-started|guides|theming)/:page*',
144-
destination: '/[platform]/:nav/:page*',
144+
destination: '/react/:nav/:page*',
145145
permanent: true,
146146
},
147147
/**
148148
* source: a url points one of the folder's names (components, getting-started, guides, theming)'s index file
149-
* destination: add '[platform]' to the beginning
149+
* destination: add '/react/' to the beginning
150150
*/
151151
{
152152
source:
153153
'/:nav(legacy-components|connected-components|components|getting-started|guides|theming)',
154-
destination: '/[platform]/:nav',
154+
destination: '/react/:nav',
155155
permanent: true,
156156
},
157157
];

docs/src/components/FlutterAuthenticatorExample.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export function FlutterAuthenticatorExample({
2222
}) {
2323
const colorAttr = 'data-amplify-color-mode';
2424
// in dev mode, `data-amplify-color-mode` will not be on the html element
25-
const colorElements = document.querySelectorAll(`[${colorAttr}]`);
25+
const colorElements =
26+
typeof window !== 'undefined'
27+
? document.querySelectorAll(`[${colorAttr}]`)
28+
: [];
2629
const themeMode = colorElements.length
2730
? colorElements[0].getAttribute(colorAttr)
2831
: 'light';

docs/src/components/Fragment.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as React from 'react';
22

33
import { Alert, Flex, Link, Placeholder } from '@aws-amplify/ui-react';
44
import dynamic, { LoaderComponent } from 'next/dynamic';
5+
import { useRouter } from 'next/router';
56

67
import { isArray } from 'lodash';
7-
import { useCustomRouter } from '@/components/useCustomRouter';
88

99
export default function Example() {
1010
return;
@@ -46,9 +46,10 @@ export const Fragment = ({
4646
platforms,
4747
useCommonWebContent,
4848
}: FragmentProps) => {
49-
const { query } = useCustomRouter();
50-
const framework = (query.platform as string) ?? 'react';
51-
const platform = getPlatform(framework, useCommonWebContent);
49+
const {
50+
query: { platform: framework = 'react' },
51+
} = useRouter();
52+
const platform = getPlatform(framework as string, useCommonWebContent);
5253
const Component = React.useMemo(() => {
5354
if (!shouldRenderFragment(platforms, platform)) {
5455
return null;

docs/src/components/InstallScripts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CopyButton } from '@/components/CopyButton';
22
import { Tabs, TabItem } from '@aws-amplify/ui-react';
3-
import { useCustomRouter } from './useCustomRouter';
3+
import { useRouter } from 'next/router';
44

55
type WebFramework = 'react' | 'vue' | 'angular';
66
type PackageManager = 'npm' | 'yarn';
@@ -47,7 +47,7 @@ interface InstallScriptsProps {
4747
export const InstallScripts = ({ framework }: InstallScriptsProps) => {
4848
const {
4949
query: { platform = 'react' },
50-
} = useCustomRouter();
50+
} = useRouter();
5151

5252
// infer framework from router if framework isn't specified
5353
if (!framework) {

docs/src/components/Layout/FrameworkChooser.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Flex, Button } from '@aws-amplify/ui-react';
22
import Link from 'next/link';
3+
import { useRouter } from 'next/router';
34

4-
import { useCustomRouter } from '@/components/useCustomRouter';
55
import { FRAMEWORKS, FRAMEWORK_DISPLAY_NAMES } from '@/data/frameworks';
66
import metaData from '@/data/pages.preval';
77
import { FrameworkLogo } from '@/components/Logo';
@@ -18,7 +18,7 @@ const FrameworkLink = ({
1818
onClick,
1919
isDisabled,
2020
}: FrameworkLinkProps) => {
21-
const { pathname, query } = useCustomRouter();
21+
const { pathname, query } = useRouter();
2222
const isCurrent = query.platform === framework;
2323
const classNames = `docs-framework-link ${isCurrent ? 'current' : ''}`;
2424
const href = pathname.includes(platformPath)
@@ -45,7 +45,7 @@ interface FrameworkChooserProps {
4545
}
4646

4747
export const FrameworkChooser = ({ onClick }: FrameworkChooserProps) => {
48-
const { pathname } = useCustomRouter();
48+
const { pathname } = useRouter();
4949

5050
const {
5151
frontmatter: { supportedFrameworks = 'react' },

docs/src/components/Layout/PageTabLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as React from 'react';
2+
import { useRouter } from 'next/router';
23

34
import { Tabs, TabItem, View } from '@aws-amplify/ui-react';
4-
import { useCustomRouter } from '@/components/useCustomRouter';
55

66
export const PageTabLayout = ({ tabComponents }) => {
77
const {
88
query: { tab = '', platform },
99
pathname,
1010
push,
11-
} = useCustomRouter();
11+
} = useRouter();
1212

1313
const defaultIndex = tab === 'props' ? 1 : 0;
1414
const [tabIndex, setTabIndex] = React.useState(defaultIndex);

docs/src/components/Layout/Sidebar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { useRouter } from 'next/router';
23
import {
34
MdOutlineChecklist,
45
MdOutlineWidgets,
@@ -29,7 +30,6 @@ import {
2930
} from '../../data/links';
3031

3132
import Link from 'next/link';
32-
import { useCustomRouter } from '@/components/useCustomRouter';
3333
import { isReactNativeEnabled } from '@/utils/featureFlags';
3434
import { FrameworkChooser } from './FrameworkChooser';
3535
import { LogoLink } from './LogoLink';
@@ -61,7 +61,7 @@ const NavLink = ({
6161
const {
6262
query: { platform = 'react' },
6363
pathname,
64-
} = useCustomRouter();
64+
} = useRouter();
6565
const isCurrent = pathname.replace('/[platform]', '') === href;
6666
const classNames = `${
6767
tertiary ? 'docs-tertiary-nav-link' : 'docs-secondary-nav-link'
@@ -81,7 +81,7 @@ const NavLink = ({
8181
};
8282

8383
const NavLinkComponentsSection = ({ heading, components, ...props }) => {
84-
const { query } = useCustomRouter();
84+
const { query } = useRouter();
8585
const { tokens } = useTheme();
8686
const { platform = 'react' } = query;
8787

@@ -137,7 +137,7 @@ const ExpanderTitle = ({ Icon, text }) => {
137137

138138
// TODO: clean up this logic
139139
const SecondaryNav = (props) => {
140-
const { pathname } = useCustomRouter();
140+
const { pathname } = useRouter();
141141
const { platform } = props;
142142
// Extract section from URL (/section/... => section)
143143
let section = pathname.split('/')[2];

docs/src/components/home/ThemeSwitcher.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState } from 'react';
2+
import { useRouter } from 'next/router';
23

34
import {
45
Card,
@@ -31,7 +32,6 @@ import {
3132
import { CgTerminal, CgLinear, CgCopyright } from 'react-icons/cg';
3233

3334
import themePreval from './themes/index.preval';
34-
import { useCustomRouter } from '@/components/useCustomRouter';
3535
import { HomeCode } from '@/components/home/HomeCode';
3636
import { CodeHighlight } from '@/components/CodeHighlight';
3737
import { trackClick } from '@/utils/track';
@@ -209,7 +209,7 @@ export const ThemeSwitcher = ({ colorMode }) => {
209209
const [theme, setTheme] = useState('default');
210210
const {
211211
query: { platform = 'react' },
212-
} = useCustomRouter();
212+
} = useRouter();
213213

214214
const isMobile = useBreakpointValue({
215215
base: true,

docs/src/components/home/sections/HeroSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import NextLink from 'next/link';
2+
import { useRouter } from 'next/router';
23
import {
34
Button,
45
Flex,
@@ -16,7 +17,6 @@ import {
1617
RiPencilRuler2Line,
1718
} from 'react-icons/ri';
1819

19-
import { useCustomRouter } from '@/components/useCustomRouter';
2020
import { CardLink } from '@/components/CardLink';
2121
import { FRAMEWORKS, FRAMEWORK_INSTALL_SCRIPTS } from '@/data/frameworks';
2222
import { FrameworkLogo } from '@/components/Logo';
@@ -25,7 +25,7 @@ import { TerminalCommand } from '@/components/InstallScripts';
2525
export const HeroSection = () => {
2626
const {
2727
query: { platform = 'react' },
28-
} = useCustomRouter();
28+
} = useRouter();
2929

3030
const showEditor = useBreakpointValue({
3131
base: false,

docs/src/components/useCustomRouter.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)