-
-
Save Leolik/e92ed7761fab3ea83dbe6ca70f964aaf to your computer and use it in GitHub Desktop.
nprogress with react-router in create-react-app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { BrowserRouter as Router, Switch } from 'react-router-dom' | |
import routes from './routes' | |
import FancyRoute from './components/tools/FancyRoute' | |
const App = props => | |
<Router> | |
<Switch> | |
{routes.map((route, i) => | |
<FancyRoute key={i} {...route} /> | |
)} | |
</Switch> | |
</Router> | |
export default App |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios' | |
import '../../node_modules/nprogress/nprogress.css' | |
import NProgress from 'nprogress' | |
import qs from 'qs' | |
const API = { | |
ROOT: process.env.NODE_ENV === 'development' ? '/' : 'https://blog.iwaterlc.com' | |
} | |
axios.defaults.baseURL = API.ROOT | |
axios.interceptors.request.use(function (config) { | |
if (config.method === 'post') { | |
config.data = qs.stringify(config.data) | |
} | |
NProgress.start() | |
return config | |
}) | |
axios.interceptors.response.use(function (config) { | |
NProgress.done() | |
return config | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { Route } from 'react-router-dom' | |
import nprogress from 'nprogress' | |
import 'nprogress/nprogress.css' | |
import './FancyRoute.css' | |
class FancyRoute extends React.Component { | |
componentWillMount () { | |
nprogress.start() | |
} | |
componentDidMount () { | |
nprogress.done() | |
} | |
render () { | |
return ( | |
<Route {...this.props} /> | |
) | |
} | |
} | |
export default FancyRoute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$progress-color: #bada55; | |
#nprogress .bar { | |
background: $progress-color; | |
} | |
#nprogress .peg { | |
box-shadow: 0 0 10px $progress-color, 0 0 5px $progress-color; | |
} | |
#nprogress .spinner-icon { | |
border-top-color: $progress-color; | |
border-left-color: $progress-color; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Home from './views/Home' | |
import About from './views/About' | |
import Blog from './views/Blog' | |
const routes = [ | |
{ | |
title: 'Home', | |
path: '/', | |
exact: true, | |
component: Home | |
}, | |
{ | |
title: 'Blog', | |
path: '/blog', | |
component: Blog | |
}, | |
{ | |
title: 'About', | |
path: '/about', | |
component: About | |
} | |
] | |
export default routes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment