@@ -5,6 +5,7 @@ import Link from 'next/link';
5
5
import { HOST } from '~/lib/config' ;
6
6
import classnames from 'classnames' ;
7
7
import { SegmentHeadline } from './Layout' ;
8
+ import extractPathWithoutFragment from '~/lib/extractPathWithoutFragment' ;
8
9
import CarbonAds from './CarbonsAds' ;
9
10
10
11
const DocLink = ( {
@@ -19,7 +20,7 @@ const DocLink = ({
19
20
url . search = '' ;
20
21
url . hash = '' ;
21
22
const stringUrl = url . toString ( ) . substr ( HOST . length , Infinity ) ;
22
- const isActive = uri === stringUrl ;
23
+ const isActive = uri === extractPathWithoutFragment ( stringUrl ) ;
23
24
return (
24
25
< Link
25
26
href = { uri }
@@ -45,7 +46,7 @@ const DocLinkBlank = ({
45
46
url . search = '' ;
46
47
url . hash = '' ;
47
48
const stringUrl = url . toString ( ) . substr ( HOST . length , Infinity ) ;
48
- const isActive = uri === stringUrl ;
49
+ const isActive = uri === extractPathWithoutFragment ( stringUrl ) ;
49
50
return (
50
51
< Link
51
52
href = { uri }
@@ -122,7 +123,7 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
122
123
const [ rotateChevron , setRotateChevron ] = useState ( false ) ;
123
124
const handleRotate = ( ) => setRotateChevron ( ! rotateChevron ) ;
124
125
const rotate = rotateChevron ? 'rotate(180deg)' : 'rotate(0)' ;
125
-
126
+ const pathWtihoutFragment = extractPathWithoutFragment ( router . asPath ) ;
126
127
return (
127
128
< div className = 'max-w-[1400px] mx-auto flex flex-col items-center' >
128
129
< section >
@@ -136,18 +137,18 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
136
137
setOpen ( ! open ) ;
137
138
} }
138
139
>
139
- { router . asPath === '/overview/what-is-jsonschema' && (
140
+ { pathWtihoutFragment === '/overview/what-is-jsonschema' && (
140
141
< h3 className = 'text-white ml-12' > Overview</ h3 >
141
142
) }
142
- { getStartedPath . includes ( router . asPath ) && (
143
+ { getStartedPath . includes ( pathWtihoutFragment ) && (
143
144
< h3 className = 'text-white ml-12' > Getting Started</ h3 >
144
145
) }
145
146
146
- { getReferencePath . includes ( router . asPath ) && (
147
+ { getReferencePath . includes ( pathWtihoutFragment ) && (
147
148
< h3 className = 'text-white ml-12' > Reference</ h3 >
148
149
) }
149
150
150
- { getSpecificationPath . includes ( router . asPath ) && (
151
+ { getSpecificationPath . includes ( pathWtihoutFragment ) && (
151
152
< h3 className = 'text-white ml-12' > Specification</ h3 >
152
153
) }
153
154
@@ -210,13 +211,14 @@ export const DocsNav = () => {
210
211
getSpecification : false ,
211
212
} ) ;
212
213
useEffect ( ( ) => {
213
- if ( getDocsPath . includes ( router . asPath ) ) {
214
+ const pathWtihoutFragment = extractPathWithoutFragment ( router . asPath ) ;
215
+ if ( getDocsPath . includes ( pathWtihoutFragment ) ) {
214
216
setActive ( { ...active , getDocs : true } ) ;
215
- } else if ( getStartedPath . includes ( router . asPath ) ) {
217
+ } else if ( getStartedPath . includes ( pathWtihoutFragment ) ) {
216
218
setActive ( { ...active , getStarted : true } ) ;
217
- } else if ( getReferencePath . includes ( router . asPath ) ) {
219
+ } else if ( getReferencePath . includes ( pathWtihoutFragment ) ) {
218
220
setActive ( { ...active , getReference : true } ) ;
219
- } else if ( getSpecificationPath . includes ( router . asPath ) ) {
221
+ } else if ( getSpecificationPath . includes ( pathWtihoutFragment ) ) {
220
222
setActive ( { ...active , getSpecification : true } ) ;
221
223
}
222
224
} , [ router . asPath ] ) ;
0 commit comments