【问题标题】:How Do I Catch And Redirect URLs Outside Angular?如何在 Angular 之外捕获和重定向 URL?
【发布时间】:2018-09-18 02:50:14
【问题描述】:

我正在尝试使用以下内容重定向无效网址

angular.module('myApp').config(function($stateProvider, $urlRouterProvider) {

 $urlRouterProvider.otherwise('/login');

  $stateProvider
    .state('test',{
      url:'/test',
      templateUrl: 'views/test.html'
    })
    .state('login',{
      url:'/login',
      templateUrl: 'views/login.html'
    });
  }).

这个网址被重定向到http://localhost/#/random,但这不是http://localhost/random,我明白了

Cannot GET /random 

我认为这是因为它在 angular 之外(没有哈希 #)。

我如何捕捉输入随机网址的人并适当地重定向他们?

我不想使用$locationProvider.html5Mode(true); 解决浏览器支持问题。

我正在使用 grunt serve 进行本地前端开发和打包,并在生产中使用 Spring Boot 运行。

【问题讨论】:

    标签: angularjs spring-boot angular-ui-router gruntjs


    【解决方案1】:

    您要么不想重定向到特定的路由或页面服务器端。因此,您需要拦截/覆盖处理页面错误并专门针对 404 的方法。

    你真的想在 spring 标记下发布这个。

    This 可以帮到你

    【讨论】:

      【解决方案2】:

      当您在地址栏中输入http://localhost/random 并按Enter 时,您将向您的服务器 发送一个GET 请求。 AngularJS 在 浏览器 中执行。所以这完全无关紧要。

      您的服务器需要做您想做的事(即重定向到/#/login),而不是发送 404。

      【讨论】:

      • 我该如何进行服务器重定向?我添加了在本地和生产环境中运行的服务器的详细信息。
      猜你喜欢
      • 2011-04-22
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 2015-03-22
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      相关资源
      最近更新 更多