expressjs重定向到角度路线不启动应用程序

时间:2017-08-08 10:36:49

标签: javascript angularjs node.js express redirect

我有以下nodejs app.js

app.use('/', routes);
app.get('some_api', routes.someApi);

app.use(function (req, res) {
    res.sendFile(path.join(__dirname, 'public', 'index.html'));
});

和angularjs app.js和index.html

$routeProvider.when('/', {
    templateUrl: '/login/login.view.html',
    controller: 'loginCtrl'
  })

angular
    .module('app')
    .config(['$routeProvider', '$locationProvider', config]);

====================

<!DOCTYPE html>
<html ng-app="app">

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
</head>

<body>
  <div ng-view></div>
  <script src="/app.js"></script>  
</body>

</html>

从expressjs api我重定向到'/',如:

module.exports.some_api = function (req, res, scope) {
   res.redirect('/');
};

但重定向后,我发现控制台中有很多错误,说明角度未定义。

看起来角度没有触发。

感谢任何帮助。 感谢。

1 个答案:

答案 0 :(得分:0)

我直接从expressjs api调用了角度路线:

module.exports.some_api = function (req, res, scope) {
   res.redirect('/#/summary');
};

它有效。

相关问题