加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 节点重定向不在角度上工作

发布时间:2020-12-17 10:22:57 所属栏目:安全 来源:网络整理
导读:嗨,我是节点的新手,我正在构建一个简单的MEAN堆栈应用程序,以减少我发送这样的前端文件的代码 app.use(express.static(path.join(__dirname,'public'))); 我还构建了一个简单的中间件,用于简单的身份验证 requireLogin = function (req,res,next) { if (!req
嗨,我是节点的新手,我正在构建一个简单的MEAN堆栈应用程序,以减少我发送这样的前端文件的代码
app.use(express.static(path.join(__dirname,'public')));

我还构建了一个简单的中间件,用于简单的身份验证

requireLogin = function (req,res,next) {
  if (!req.user) {
      console.log('redirecting :)');
      res.redirect('/');
  } else {
      next();
  }
};

app.use('/rooms',requireLogin);

我正试图在有角度的路线上使用这个中间件.
但是当我在我的角度应用程序中导航时它不起作用(当我直接将URL放到地址栏时它可以工作)我还删除了由角度添加的/#/.

$locationProvider.html5Mode({
    enabled: true,requireBase: false
});

我正在使用ui-router进行路由.

您应该在angular.js应用程序上重定向角度,而不是重定向.例如,
requireLogin = function (req,next) {
  if (!req.user) {
      console.log('User does not exist.');
      return false;
      // 
  } else {
      next();
  }
};

app.use('/rooms',requireLogin);

然后,除非有用户登录,否则/ rooms将无法访问.

Backend routes (express ones): Those are the routes that an end user won’t have to know about or even use them (your angular app will use them to communicate with the backend to work with its data but an end user wouldn’t put them directly on the browser)).

Frontend routes (angular ones): Are the routes that maps to different pages of your application and because of that,end users can use them to access some parts of your application directly.

阅读Express.js or angular for handling routes in a MEAN application?了解更多详情.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读