npm run build
之后,客户端停止重定向到某些页面(成功登录后/about
,/home
等)。
然而,在开发过程中,每个阶段都是成功的。
项目结构:
--client
--build
--src
--containers
--App.js
index.js
--other dev stuff
--server
--server.js
--routes
--svrRoutes.js
--other stuff
App.js
import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
class App extends Component {
constructor(props) {
//
}
render() {
return (
<div>
<Router>
<Switch>
<Route path="/" exact component={Login} />
<Route path="/dashboard" component={withAuthentication(Dashboard)} />
<Route path="/about" component={About} />
<Route path="/home" component={withAuthentication(Home)} />
<Route path="/searchtweets" component={SearchTweets} />
</Switch>
</Router>
<Footer1/>
</div>
);
}
}
export default App;
svrRoutes.js
let {
addNewData,
getData,
getDataByID,
updateDataByID,
deleteDataByID,
addNewUser,
getUserByID,
getUser,
updateUserByID,
getDataByManID
} = require('../controllers/svrController');
let {
getTweetData
} = require('../twitter');
const routes = (app) => {
app.route('/data')
.get((req, res, next) => {
// middleware
console.log(`Request from: ${req.originalUrl}`);
console.log(`Request type: ${req.method}`);
next();
}, getData)
// POST endpoint
.post(addNewData);
app.route('/data/twitter')
.get((req, res) => {
getTweetData(req, res);
});
app.route('/data/:dataId')
// get specific data Item
.get(getDataByID)
// put request
.put(updateDataByID)
// delete request
.delete(deleteDataByID);
app.get('/getdata', getDataByManID);
app.route('/user')
.post(addNewUser)
.get((req, res, next) => {
// middleware
console.log(`Request from: ${req.originalUrl}`);
console.log(`Request type: ${req.method}`);
next();
}, getUser);
app.route('/user/:userId')
.get(getUserByID)
// put request
.put(updateUserByID);
app.route('/man/:userId')
.get(getDataByManID);
};
module.exports = routes;
这是GitHub上的仓库,我认为这比仅发布片段要好,因为我可能会错过一些重要的事情。 https://github.com/aaronjohn2/EmployerDatabaseViewApplication