如果插入了数据,我想重定向到另一个页面,但由于某种原因它不起作用。请告诉我你怎么能做到这一点?有不同的方法,但即使是 argulatorjs 也无济于事。
let express = require("express");
let app = express();
let port = 3000;
let bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
let angular = require('angular');
let mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost:27017/test");
let nameSchema = new mongoose.Schema({
name: String,
login: String,
password: String,
authorization: Boolean
});
let User = mongoose.model("User", nameSchema);
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.post("/addname", (req, res) => {
let myData = new User(req.body);
myData.save()
.then(item => {
res.send("Вы успешно зарегистрировались, перенаправление...");
$window.location.href = '/CA.html';
})
.catch(err => {
res.status(400).send("Что-то пошло не так");
});
});
app.listen(port, () => {
console.log("Server listening on port " + port);
});
答案 0 :(得分:0)
您可以像这样在端点中使用它;
app.get('/stackoverflow', (req, res) => {
// Redirect goes to stackoverflow
res.redirect('https://stackoverflow.com/');
})