Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/web/ui/src/App.tsx
4094 views
1
import { PathPrefixContext } from './contexts/PathPrefixContext';
2
import Router from './Router';
3
4
import styles from './App.module.css';
5
6
/**
7
* getBasePath retrieves the base path of the application by looking at the
8
* <base> HTML element in the HTML header. If there is no <base> element or the
9
* <base> element is empty, getBaseURL returns "/".
10
*/
11
function getBasePath(): string {
12
const elements = document.getElementsByTagName('base');
13
if (elements.length !== 1) {
14
return '/';
15
}
16
17
// elements[0].href will be a full URL, but we just want to extract the path
18
// portion.
19
return new URL(elements[0].href).pathname;
20
}
21
22
function App() {
23
const basePath = getBasePath();
24
25
return (
26
<PathPrefixContext.Provider value={basePath}>
27
<div className={styles.app}>
28
<Router basePath={basePath} />
29
</div>
30
</PathPrefixContext.Provider>
31
);
32
}
33
34
export default App;
35
36