如何将根页面重定向到angularjs中的另一个URL

时间:2014-05-29 09:34:33

标签: javascript angularjs redirect

我希望我的应用程序从www.abc.com/#!/abc开始,目前当我输入www.abc.com时,它会重定向到www.abc.com/#!。以下是我的index.html

<!-- views/index.html -->
<section data-ng-controller="IndexController">
    <h1 mean-token="'home-default'">This is the home view</h1>
</section>


// controllers/index.js
angular.module('mean.system').controller('IndexController', ['$scope', 'Global', function ($scope, Global) {
    $scope.global = Global;
}]);

我尝试从

更改路线templateurl
        $stateProvider              
            .state('home', {
                url: '/',
                templateUrl: 'public/system/views/index.html'
            })

        $stateProvider              
            .state('home', {
                url: '/',
                templateUrl: 'public/abc/views/abc.html'
            })

从功能的角度解决了我的问题,但我是否可以从system / views / index.html内部重定向到另一个网址?

2 个答案:

答案 0 :(得分:2)

在您的配置部分添加$urlRouterProvider

的依赖项

$urlRouterProvider.when('/', '/abc');

答案 1 :(得分:0)

是的,您可以重定向到其他网址(在ui-router术语中称为状态!)。这是你如何做到的......

在index.html文件中

<button type="button" ui-sref="login">Go to login state</button>

在控制器中

.state('login', {
  url: "/login",
  templateUrl: "views/login.html"
})

创建login.html文件

<!-- views/login.html -->
<section data-ng-controller="LoginController">
        <h1 mean-token="'login-default'">This is the login view</h1>
</section>

瞧!

您可以学习更多here