Created
September 2, 2020 19:46
-
-
Save niikkiin/7363c5c9b73561eb5a35aebecc4e6536 to your computer and use it in GitHub Desktop.
React App Set Up with Layout for Router
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"; | |
// router | |
import { BrowserRouter as Router, Switch } from "react-router-dom"; | |
// routes | |
import AuthRoute from "routes/AuthRoute"; | |
// pages | |
import Login from "pages/auth/Login"; | |
function App() { | |
return ( | |
<Router> | |
<Switch> | |
<AuthRoute exact path="/" component={Login} /> | |
</Switch> | |
</Router> | |
); | |
} | |
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' | |
// import PropTypes from 'prop-types'; | |
const AuthLayout = ({children}) => { | |
return ( | |
<div className="bg-pink-100"> | |
{children} | |
</div> | |
) | |
} | |
AuthLayout.propTypes = { | |
} | |
export default AuthLayout; |
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 PropTypes from 'prop-types' | |
// router | |
import { Route } from "react-router-dom"; | |
// layout | |
import AuthLayout from "layouts/AuthLayout"; | |
const AuthRoute = ({ component: Component, ...rest }) => { | |
return ( | |
<Route | |
{...rest} | |
render={(props) => ( | |
<AuthLayout> | |
<Component {...props} /> | |
</AuthLayout> | |
)} | |
/> | |
); | |
}; | |
AuthRoute.propTypes = {}; | |
export default AuthRoute; |
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
Show hidden characters
//setup inside client folder | |
//for making absolute urls | |
{ | |
"compilerOptions": { | |
"baseUrl": "./src" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment