不能导航到URL UI路由器状态 [英] Can't navigate to ui-router state with URL
问题描述
我正在使用的用户界面路由器一个简单的角度应用程序。我有选择,然后在编辑有关出版商一对夫妇的状态。相关配置:
I'm working on a simple angular application using 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'
})
在选择出版商的状态我有可用的出版商的大名单。他们每个人都必然会触发以下功能在我的控制器的NG-click事件:
Inside the select-publisher state I have a big list of available publishers. Each one of them is bound to an ng-click event that triggers the following function in my controller:
$scope.selectPublisher = function(publisher) {
publisherService.setSelectedPublisher(publisher);
$state.go('publisher.details', {id: publisher.Id});
};
这工作得很好,并带我到publisher.details状态,并呈现适当的视图。此时的URL在浏览器指向本地主机:1337 /超级管理员#/出版商/ 39 /细节
,其中39是我选择的发布商ID
This works just fine and takes me to the publisher.details state and renders the proper view. 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的细节状态(或任何其他国家)。
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. 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.
值得注意的是,我有一个包罗万象毕竟我的状态定义的所有路径:
Worth noting is that I do have a catch all route defined after all of my states:
$urlRouterProvider.otherwise('/select-publisher');
我假设由于某种原因,这是被触发,但我不能理由,为什么导航使用我的应用程序的工作原理为 $ state.go
我在我的控制器都表示,以及使用 UI-SREF指令
在我的HTML模板而不是通过直接导航到该URL。
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.
推荐答案
也许是因为缺少斜线的网址: /出版商/ {ID:INT}
Maybe it's because of missing slash url: /publisher/{id:int}
这篇关于不能导航到URL UI路由器状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!