简体   繁体   English

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

[英]How to redirect root page to another url in angularjs

I want my app to start with www.abc.com/#!/abc currently when I type www.abc.com it redirects to www.abc.com/#!. 我希望我的应用当前以www.abc.com/#!/abc开头,当我键入www.abc.com时,它会重定向到www.abc.com/#!。 Following are my index.html 以下是我的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;
}]);

I tried changing the routes templateurl from 我尝试从更改路线templateurl

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

to

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

which solved my problem from functionality point of view but can I aswell redirect to another url from inside system/views/index.html? 从功能的角度解决了我的问题,但是我还能从system / views / index.html内部重定向到另一个URL吗?

在您的配置部分添加$urlRouterProvider依赖$urlRouterProvider

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

Yes, you can redirect to other url's (called states in ui-router terminology!). 是的,您可以重定向到其他URL(在UI路由器术语中称为状态!)。 This is how you do it... 这就是你的做法...

In index.html file 在index.html文件中

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

In controller 在控制器中

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

Create login.html file 创建login.html文件

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

And voila! 瞧!

You can learn a lot more here ! 您可以在这里学到更多!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM