diff --git a/src/components/application-loader/application-loader.tsx b/src/components/application-loader/application-loader.tsx index 2773ce839..081b80c95 100644 --- a/src/components/application-loader/application-loader.tsx +++ b/src/components/application-loader/application-loader.tsx @@ -5,18 +5,17 @@ SPDX-License-Identifier: AGPL-3.0-only */ import React, { Suspense, useCallback, useEffect, useState } from 'react' -import { useLocation } from 'react-router' +import { useFrontendBaseUrl } from '../../hooks/common/use-frontend-base-url' import './application-loader.scss' import { createSetUpTaskList, InitTask } from './initializers' import { LoadingScreen } from './loading-screen' export const ApplicationLoader: React.FC = ({ children }) => { - const { pathname } = useLocation() + const frontendUrl = useFrontendBaseUrl() const setUpTasks = useCallback(() => { - const baseUrl: string = window.location.pathname.replace(pathname, '') - return createSetUpTaskList(baseUrl) - }, [pathname]) + return createSetUpTaskList(frontendUrl) + }, [frontendUrl]) const [failedTitle, setFailedTitle] = useState('') const [doneTasks, setDoneTasks] = useState(0) diff --git a/src/hooks/common/use-frontend-base-url.ts b/src/hooks/common/use-frontend-base-url.ts new file mode 100644 index 000000000..c11cd6e03 --- /dev/null +++ b/src/hooks/common/use-frontend-base-url.ts @@ -0,0 +1,13 @@ +/* +SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file) + +SPDX-License-Identifier: AGPL-3.0-only +*/ + +import { useLocation } from 'react-router' + +export const useFrontendBaseUrl = (): string => { + const { pathname } = useLocation() + + return window.location.pathname.replace(pathname, '') +}