简体   繁体   English

无法使用URL导航到ui-router状态

[英]Can't navigate to ui-router state with URL

I'm working on a simple angular application using ui-router. 我正在使用ui-router进行简单的角度应用。 I have a couple states for selecting and then editing information about a publisher. 我有几种状态可以选择然后编辑有关发布者的信息。 The relevant config: 相关配置:

            .state('select-publisher', {
                url: '/select-publisher',
                templateUrl: '/Content/superadmin/src/templates/publishers/publishers.html'
            })

            .state('publisher', {
                abstract: true,
                url: 'publisher/{id:int}',
                templateUrl: '/Content/superadmin/src/templates/publishers/publisher.html'
            })
            .state('publisher.details', {
                url: '/details',
                templateUrl: '/Content/superadmin/src/templates/publishers/details.html'
            })
            .state('publisher.ad-tags', {
                url: '/ad-tags',
                templateUrl: '/Content/superadmin/src/templates/publishers/ad-tags.html'
            })
            .state('publisher.native-ads', {
                url: '/native-ads',
                templateUrl: '/Content/superadmin/src/templates/publishers/native-ads.html'
            })

Inside the select-publisher state I have a big list of available publishers. 在select-publisher状态中,我有一个很大的可用发布者列表。 Each one of them is bound to an ng-click event that triggers the following function in my controller: 它们中的每一个都绑定到ng-click事件,该事件在我的控制器中触发以下功能:

 $scope.selectPublisher = function(publisher) {
     publisherService.setSelectedPublisher(publisher);
     $state.go('publisher.details', {id: publisher.Id});
 };

This works just fine and takes me to the publisher.details state and renders the proper view. 这很好用,并将我带到publisher.details状态并呈现正确的视图。 At this point the URL in my browser points to localhost:1337/superadmin#/publisher/39/details where 39 is the ID of the publisher that I selected. 此时,我的浏览器中的URL指向localhost:1337/superadmin#/publisher/39/details其中39是我选择的发布者的ID。

The problem is, if I refresh this page or attempt to navigate directly to it by pasting the URL into the browser from another area of the application, I am ALWAYS taken back to the select-publisher state. 问题是,如果我刷新此页面或尝试通过将URL从应用程序的其他区域粘贴到浏览器中直接导航到该页面,我将始终返回到select-publisher状态。 I would like to be able to configure my states such that I am able to navigate to the details state (or any other state) based on URL. 我希望能够配置我的状态,以便我能够基于URL导航到详细状态(或任何其他状态)。

Worth noting is that I do have a catch all route defined after all of my states: 值得注意的是,我确实在所有状态之后都定义了捕获所有路径:

$urlRouterProvider.otherwise('/select-publisher');

I'm assuming that for some reason this is being triggered but I can't reason as to why navigation works in my app using either $state.go as I have indicated in my controller as well as using ui-sref directive in my HTML templates but not through navigating directly to the URL. 我假设由于某种原因这是触发但我无法$state.go为什么导航在我的应用程序中使用$state.go因为我在我的控制器中指示以及在我的HTML中使用ui-sref directive模板,但不是通过直接导航到URL。

也许是因为缺少斜杠网址: /publisher/{id:int}

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

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