|
1 | 1 | import { Document } from "@dzcode.io/api/dist/app/types/legacy"; |
| 2 | +import { LanguageEntity } from "@dzcode.io/models/dist/language"; |
2 | 3 | import { isLoaded } from "@dzcode.io/utils/dist/loadable"; |
3 | 4 | import * as Sentry from "@sentry/browser"; |
4 | 5 | import { listToTree } from "l2t"; |
| 6 | +import { matchPath } from "react-router-dom"; |
5 | 7 | import { ThunkResult } from "src/apps/main/redux"; |
6 | 8 | import { DocumentationState } from "src/apps/main/redux/reducers/documentation"; |
7 | 9 | import { LearnPageState } from "src/apps/main/redux/reducers/learn-page"; |
8 | 10 | import { SidebarTreeItem } from "src/apps/main/types"; |
9 | 11 | import { hasInCollection } from "src/common/utils"; |
10 | 12 | import { fetchV2 } from "src/common/utils/fetch"; |
| 13 | +import { history } from "src/common/utils/history"; |
| 14 | +import { urlLanguageRegEx } from "src/common/utils/language"; |
11 | 15 |
|
12 | 16 | /** |
13 | 17 | * Fetches the list of documents for the sidebar |
@@ -163,9 +167,11 @@ const fetchCurrentDocumentAuthors = |
163 | 167 | */ |
164 | 168 | export const fetchCurrentDocument = |
165 | 169 | (): ThunkResult<LearnPageState | DocumentationState> => async (dispatch, getState) => { |
166 | | - const slug = location.pathname |
167 | | - .substring(location.pathname.indexOf("/", 1) + 1) |
168 | | - .replace(/\/$/, ""); |
| 170 | + const match = matchPath<{ lang?: LanguageEntity["code"]; slug: string }>( |
| 171 | + history.location.pathname, |
| 172 | + { path: `${urlLanguageRegEx}/Learn/:slug(.*)` }, |
| 173 | + ); |
| 174 | + const slug = match?.params.slug || ""; |
169 | 175 | const cashedDocument = hasInCollection<Document>(getState().documentation.list, "slug", slug, [ |
170 | 176 | ["content"], |
171 | 177 | ]); |
|
0 commit comments