首页 > 解决方案 > Angular JS 1中的$ location:badpath时如何将url重定向到默认值

问题描述

当我输入一个 '\' 之后是另一个 '\' 的 url 时。例如:http://localhost:8080/#!//test。它将产生 $location:badpath 的错误。如果用户这样做,如何将其重定向到默认路由?

app.config(function ($routeProvider, $httpProvider) {
$routeProvider
    .when('/test', {
        templateUrl: 'project/view/test.html',
        controller: 'TestController'
    })
    .otherwise(
        {
            redirectTo: '/dashboard'
        }
    );

标签: javascriptangularjs

解决方案


推荐阅读