javascript - Why is there no need to assign the value of req.session to the object in render before the page can recognize it?
阿神
阿神 2017-05-16 13:32:28
0
1
561

Used the session middleware in express,

There is no user in the object!

Req.session.user is assigned a value before redirection

This is the route
.png](/img/bVNmO9)

This is the render page. How did you get this user value? Why don't we need to assign a user value to the incoming object in render? How does it work? Why do some need it?

In the next page that this page jumps to, if no value is assigned, it will not be recognized.

exports.publish=function (req,res,next) {
    return res.render('publish',{
        key:'publish',
        user:req.session.user
    });
}
阿神
阿神

闭关修行中......

reply all(1)
我想大声告诉你

The poster’s question is just one question, callback assignment in node
The value of callback in node is different from the general callback. It cannot be understood as a general callback. The general callback is assigned a value. This is not an assignment, but a method. A value is directly assigned to User
analogous to

var user.save=function(fn){
    //产生了一个值,test
    fn(test);
}

According to the above idea, if you don’t understand, ask me again.
User.newUserSave generates a value and assigns it to user

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template