/
App.js
71 lines (66 loc) 路 1.99 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React from 'react';
import { NavLink, NavContent, NavNotFoundBoundary, useLoadingRoute } from 'react-navi';
import { MDXProvider } from '@mdx-js/tag';
import './App.css';
function App() {
let loadingRoute = useLoadingRoute()
return (
<AppLayout isLoading={loadingRoute}>
<NavNotFoundBoundary render={renderNotFound}>
<MDXProvider components={{
// Use Navi's <NavLink> component to render links in
// Markdown files, ensuring navigation is handled by Navi.
a: NavLink,
}}>
<NavContent />
</MDXProvider>
</NavNotFoundBoundary>
</AppLayout>
);
}
function AppLayout({ children, isLoading }) {
return (
<div className="App">
<div
// Only add the `active` class to this element while the
// next page is loading, triggering a CSS animation to
// show or hide the loading bar.
className={`
App-loading-indicator
${isLoading ? 'active' : ''}
`}
/>
<header className="App-header">
<nav className="App-nav">
<NavLink href='/' activeClassName='active' exact>
Home
</NavLink>
<NavLink href='/about/' activeClassName='active'>
About
</NavLink>
<NavLink href='/404/' activeClassName='active'>
404
</NavLink>
</nav>
</header>
<main>
{children}
</main>
</div>
)
}
// Note that create-react-navi-app will always show an error screen when this
// is called. This is because the underlying react-scripts package show
// the error screen when a NotFoundError is thrown, even though it's caught
// by <NavNotFoundBoundary>. To see the error rendered by this function,
// you'll just need to close the error overlay with the "x" at the top right.
function renderNotFound() {
return (
<AppLayout>
<div className='App-error'>
<h1>404 - Not Found</h1>
</div>
</AppLayout>
)
}
export default App;