我正在尝试使用 angular 和 nodejs 构建和 web。我在包含登录和注册表单的/home
路径上加载 Angular。/
这是我的角度配置:
window.app.config(['$routeProvider', '$locationProvider',
function($routeProvider,$locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
$routeProvider.
when('/profile', {
templateUrl: '/views/account.html',
}).
when('/edit', {
templateUrl: '/views/edit.html',
}).
when('/home', {
templateUrl: 'views/index.html'
}).
when('/signout', {
templateUrl: 'views/signout.html'
//on this view i load a controller which submits a form to /signout
}).
otherwise({
redirectTo: '/home'
});
}
]);
在服务器端路由:
app.get('/',function(){
res.render('index',{
user: req.user? req.user:'guest'
});
});
app.post('/login',function(){
//if success redirect to /home
//if fails redirect to /
});
app.get('/auth/facebook', passport.authenticate('facebook', { scope: [ 'email', 'user_about_me', 'read_stream', 'publish_actions'], failureRedirect: '/' }));
app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/' }), users.authCallback);
app.get('/signout',function(){
//signing out the user here...and redirects to /
});
app.get('/home',function(req,res){
res.render('users/home',{
user: req.user? req.user:'guest',
message: req.flash('error')
})
});
app.get('/profile',function(req,res){
res.render('users/home',{
user: req.user? req.user: 'guest',
message: req.flash('error')
})
});
app.get('/edit',function(req,res){
res.render('users/home',{
user: req.user? req.user:'guest',
message: req.flash('error')
})
});
如果我点击facebook auth它发送给我,我如何通过点击 url/home
上的链接发送请求,/auth/facebook
因为 Angular 路由。Angular 阻止向服务器发送请求,它只是转到 url ,我尝试通过替换来删除. 结果是一样的,只是那里没有加载视图。/home
/home
/home
/