In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Create webpack.config.js at root folder and paste following contents for less, css etc.
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry : './src/index.js',
output : {
path : path.resolve(__dirname , 'dist'),
filename: 'index_bundle.js'
},
module : {
rules : [
{test : /\.(js)$/, use:'babel-loader'},
{test : /\.less$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'less-loader' }
]
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
}
]
},
mode:'development',
plugins : [
new HtmlWebpackPlugin ({
template : './public/index.html'
})
]
}
Create babel.config.js at root folder and paste following contents
module.exports = {
presets: [ "@babel/preset-env", "@babel/preset-react" ],
plugins: [ "@babel/plugin-transform-arrow-functions", "@babel/plugin-proposal-class-properties" ]
}
Install following two packages
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0"
Then create routes.js file and have following contents in the file
import App from '../App';
import Home from '../components/home';
import Contact from '../components/contact';
import About from '../components/about';
import React from 'react';
import { BrowserRouter, Route, Switch, Link } from 'react-router-dom';
import Header from '../components/header';
import Footer from '../components/footer';
function Routes() {
return (
<BrowserRouter>
<div>
<Header />
<hr/>
<div className="flex-line">
<div className="content">
<Switch>
<Route exact path='/' component={App}/>
<Route path='/home' component={Home}/>
<Route path='/contact' component={Contact}/>
<Route path='/about' component={About}/>
</Switch>
</div>
</div>
<Footer />
</div>
</BrowserRouter>
)
}
export default Routes;
npm i redux
npm i react-redux
npm i redux-thunk
├── redux
│ ├── actions # All actions
│ ├── reducers # All reducers
│ └── types # All action types
│ └── store.js # Js file for store
└── ...
Create a folder inside components
├── components
│ ├── auth
│ ├── index.js
└── ...
Paste the following contents to the file
import React, { cloneElement, Children } from 'react'
import { Route, Redirect } from 'react-router-dom'
const PrivateRoute = ({ children, authed, ...rest }) =>
<Route
{...rest}
render={(props) => localStorage.getItem('name') === 'true' ?
<div>
{Children.map(children, child => cloneElement(child, { ...child.props }))}
</div>
:
<Redirect to={{ pathname: '/', state: { from: props.location } }} />}
/>
export default PrivateRoute
npm i bootstrap
In index.js add following lines
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import '../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js';