有没有一种方法可以使用angular ui路由器不显示#!/login? [英] Is there a way using angular ui router not show #!/login?

查看:105
本文介绍了有没有一种方法可以使用angular ui路由器不显示#!/login?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用Angular ui路由器调用$state.go('login'),则子URL如下所示.

If I call $state.go('login') using Angular ui router, the suburl looks like this.

是否可以隐藏#!/login?这是第一次使用角度ui路由器,我什至不知道它是可能的. 所以我只想看localhost:3000/

Is there a way to hide #!/login? It's first time to use angular ui router and I dont know even it's possible. So I want to see only localhost:3000/

推荐答案

只需在配置状态时不定义url属性,就可以在ui-router中创建没有url的状态.

You can create a state without an url in ui-router, by simply not defining the url property when configuring your states.

像这样:

angular.module('app').config(function ($stateProvider) {
    $stateProvider.state('login', {
        component: 'loginComponent'
    });
});

您将无法直接导航到登录URL.但是您仍然可以使用ui-sref$state.go('login')进行导航.

You wont be able to navigate directly to the login url. But you'll still be able to use ui-sref or $state.go('login') to navigate.

如果您仍然希望能够直接导航到登录页面,则除了上面的配置URL之外,还可以配置其他登录状态.

If you still want to be able to navigate directly to the login page, you can configure another login state in addition to the above, where you specify the url property.

angular.module('app').config(function ($stateProvider) {
    $stateProvider.state('login', {
        component: 'loginComponent'
    }).state('loginDirect', {
        url: '/login',
        component: 'loginComponent'
    });
});

这篇关于有没有一种方法可以使用angular ui路由器不显示#!/login?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆