docs icon indicating copy to clipboard operation
docs copied to clipboard

[Docs Site] Determine "active" links with asPath instead of pathname

Open ericclemmons opened this issue 4 years ago • 2 comments

Hi! 👋

When working on the Amplify UI docs, my pages are powered by [[...slugs]].tsx. pathname returns this value, so none of SecondaryNav is active.

Using asPath correctly returned /ui/... strings, making active finally return true as expected.

Here is the diff that solved my problem:

diff --git a/node_modules/amplify-docs/src/components/SecondaryNav/index.tsx b/node_modules/amplify-docs/src/components/SecondaryNav/index.tsx
index 5a13939..34f4c54 100644
--- a/node_modules/amplify-docs/src/components/SecondaryNav/index.tsx
+++ b/node_modules/amplify-docs/src/components/SecondaryNav/index.tsx
@@ -16,7 +16,7 @@ import {Container} from "../Container";
 
 export default function SecondaryNav({platform, pageHasMenu}) {
   const router = useRouter();
-  const path = router.pathname;
+  const path = router.asPath;
 
   return (
     <SecondaryNavStyle id="secondary-nav">

This issue body was partially generated by patch-package.

ericclemmons avatar Jul 12 '21 06:07 ericclemmons

Thanks @ericclemmons! Yes I agree with using asPath here. I'll make a PR to merge this change next week.

jakeburden avatar Oct 08 '21 19:10 jakeburden

Do we still want to do this @jakeburden ?

mauerbac avatar May 08 '22 18:05 mauerbac

Looks like this is fixed!

nearestnabors avatar Aug 15 '22 21:08 nearestnabors