[英]How can I set a route like Instagram? localhost:3000/USERNAME
I want to set my routes like Instagram (instagram.com/username)我想设置我的路线,如 Instagram (instagram.com/username)
I tried this:我试过这个:
router.get('/:name', loggedin, function (req, res, next) {
res.render('profile', {"Request name": req.user});
});
But if I visit my /logout route or any other route when I'm logged in it also render the profile Page instead of logging out但是,如果我在登录时访问我的 /logout 路由或任何其他路由,它也会呈现个人资料页面而不是注销
Extend your route by /logout
to avoid using if statements and make use of POST requests.通过
/logout
扩展您的路线以避免使用 if 语句并使用 POST 请求。 You generally want most of your user-actions to be POST instead of GET requests.您通常希望大多数用户操作是 POST 而不是 GET 请求。
router.post('/:name/logout', loggedin, function (req, res, next) {
// Logout user here
// Return data or redirect
});
Well just use a if
statement then.那么只需使用
if
语句。
router.get('/:name', loggedin, function (req, res, next) {
if(req.params.name == "logout"){
//do something...
return res.json("logged out");
}
res.render('profile', {"Request name": req.user});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.