AngularJS重定向删除

AngularJS重定向删除,angularjs,html,url,redirect,razor,Angularjs,Html,Url,Redirect,Razor,我的a.cshtml文件中有一个视图,其中有一个更新按钮 “更新”按钮起作用,但我想重定向到主目录 在我的.js文件中,我第一次 success(function (data) { //Showing Success message alert("Incident Added"); $location.path("\Home"); }) 该链接从/Home/Create转到/Home/Create/Home,只是停留在那里。我想让

我的a.cshtml文件中有一个视图,其中有一个更新按钮 “更新”按钮起作用,但我想重定向到主目录

在我的.js文件中,我第一次

    success(function (data) {
        //Showing Success message
        alert("Incident Added");
        $location.path("\Home");
    })
该链接从/Home/Create转到/Home/Create/Home,只是停留在那里。我想让它回到我的主目录。基本上是在创建后返回主视图

我也试过这个

        success(function (data) {
        //Showing Success message
        alert("Incident Added");
        $scope.$apply(function () {
            $location.path("/Home");
        });
    })

之后,url没有添加/Home,但它与/Home/Create保持一致,没有“转到/Home”。我想知道我需要做什么才能让它回家。或者更确切地说,学习如何正确执行重定向。

假设您的$routProvider将此设置设置为home

  $routeProvider

    .when('/', { templateUrl:'home.html',controller:'CtrlHome'})
你应该能够使用

 $location.path("/");

$location服务专为单页应用程序设计,易被误解

如果您希望基本HTTP重定向到MVC路由,例如your.app.com/Home,请使用$window.location

$window.location.href = "/Home";
在app.config中,您可以使用$routeProvider声明将用户发送到哪里,具体取决于用户输入的url。您/家庭的模板URL是什么?在这里,您可以阅读有关$routeParams的更多信息