Created
May 20, 2017 19:51
-
-
Save HappyZombies/72c526d1c2d229ae46f64be55bc67324 to your computer and use it in GitHub Desktop.
If the app has not been setup yet (based on the /setup/setup-config/ express endpoint), redirect them to the setup page no matter what URL they go to.
This file contains 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, {Component} from 'react' | |
import {BrowserRouter, Switch, Route} from 'react-router-dom' | |
import Setup from '../pages/Setup' | |
import Routes from '../routes' | |
class App extends Component { | |
constructor (props) { | |
super(props) | |
this.state = {setup: true} // assume true first... | |
} | |
componentDidMount () { | |
fetch('/setup/setup-config') // this is an express url that returns {setup: false} or {setup: true} | |
.then((responseJson) => { | |
if (responseJson.ok) { | |
responseJson.json().then(json => { | |
this.setState({ | |
setup: json.setup | |
}) | |
}) | |
} | |
}) | |
.catch((error) => { | |
console.error(error) | |
}) | |
} | |
render () { | |
if (this.state.setup) { | |
return (<BrowserRouter> | |
<Routes /> | |
</ BrowserRouter>) | |
} | |
return (<BrowserRouter> | |
<Switch> | |
<Route exact path='*' component={Setup} /> | |
</Switch> | |
</ BrowserRouter>) | |
} | |
} | |
export default App |
This file contains 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' | |
export default () => { | |
return (<h2>Setup Page</h2>) | |
} |
This file contains 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, {Component} from 'react' | |
class Home extends Component { | |
render () { | |
return ( | |
<div> | |
Welcome To Home Page | |
</div> | |
) | |
} | |
} | |
export default Home |
This file contains 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 ReactDOM from 'react-dom' | |
import registerServiceWorker from './registerServiceWorker' | |
import App from './components/App' | |
ReactDOM.render(<App />, | |
document.getElementById('root') | |
) | |
registerServiceWorker() |
This file contains 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' | |
export default () => { | |
return (<h2>Not Found</h2>) | |
} |
This file contains 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 { Switch, Route } from 'react-router-dom' | |
import Setup from './pages/Setup' | |
import Home from './pages/Home' | |
import NotFound from './pages/NotFound' | |
const Routes = () => ( | |
<Switch> | |
<Route exact path='/' component={Home} /> | |
<Route exact path='/setup' component={Setup} /> | |
<Route exact path='*' component={NotFound} /> | |
</Switch> | |
) | |
export default Routes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gistfile1.txt should be Setup.js, the setup page