File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1- import React from 'react' ;
21import { PageMetadata } from '@docusaurus/theme-common' ;
32import Layout from '@theme/Layout' ;
3+ import React from 'react' ;
44
55export default function NotFound ( ) {
66 return (
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import {
1717} from '@docusaurus/theme-common/internal' ;
1818import Translate , { translate } from '@docusaurus/Translate' ;
1919import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
20+ import { useLocation } from '@docusaurus/router' ;
2021import {
2122 useAlgoliaThemeConfig ,
2223 useSearchResultUrlProcessor ,
@@ -120,6 +121,8 @@ function SearchPageContent() {
120121 const documentsFoundPlural = useDocumentsFoundPlural ( ) ;
121122 const docsSearchVersionsHelpers = useDocsSearchVersionsHelpers ( ) ;
122123 const [ searchQuery , setSearchQuery ] = useSearchQueryString ( ) ;
124+ const location = useLocation ( ) ;
125+ const notFound = new URLSearchParams ( location . search ) . get ( 'not-found' ) ;
123126 const initialSearchResultState = {
124127 items : [ ] ,
125128 query : null ,
@@ -302,7 +305,14 @@ function SearchPageContent() {
302305 </ Head >
303306
304307 < div className = "container margin-vert--lg" >
305- < h1 > { getTitle ( ) } </ h1 >
308+ { notFound ? (
309+ < >
310+ < h1 > Page Not Found</ h1 >
311+ < h2 > { getTitle ( ) } </ h2 >
312+ </ >
313+ ) : (
314+ < h1 > { getTitle ( ) } </ h1 >
315+ ) }
306316
307317 < form className = "row" onSubmit = { ( e ) => e . preventDefault ( ) } >
308318 < div
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ function scrollOpenApiSidebarItemIntoView() {
7676}
7777
7878function redirectOpenApiDocs ( ) {
79- const { hash, pathname } = new URL ( window . location . href ) ;
79+ const { hash, pathname, origin } = new URL ( window . location . href ) ;
8080
8181 // TODO change to '/api/v2'
8282 if ( pathname . replace ( / \/ $ / , '' ) !== '/api/v2-new' ) {
@@ -86,13 +86,21 @@ function redirectOpenApiDocs() {
8686 const sidebarItems = document . querySelectorAll ( '[data-altids]' ) ;
8787
8888 if ( hash . startsWith ( '#/reference/' ) || hash . startsWith ( '#tag/' ) ) {
89+ let matched = false ;
90+
8991 for ( const item of sidebarItems ) {
9092 const ids = item . getAttribute ( 'data-altids' ) . split ( ',' ) ;
93+
9194 if ( ids . find ( ( variant ) => variant === hash ) ) {
95+ matched = true ;
9296 item . click ( ) ;
9397 setTimeout ( ( ) => scrollOpenApiSidebarItemIntoView ( ) , 200 ) ;
9498 }
9599 }
100+
101+ if ( ! matched ) {
102+ window . location . href = `${ origin } /search?q=${ hash . slice ( 1 ) } ¬-found=1` ;
103+ }
96104 }
97105}
98106
You can’t perform that action at this time.
0 commit comments