我正在使用ui路由器的一個簡單的角度應用程序。我有幾個州選擇和編輯有關出版商的信息。相關配置:無法導航到與URL的UI路由器狀態
.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事件:
$scope.selectPublisher = function(publisher) {
publisherService.setSelectedPublisher(publisher);
$state.go('publisher.details', {id: publisher.Id});
};
這工作得很好,帶我到publisher.details狀態,並呈現適當的視圖。此時,瀏覽器中的URL指向localhost:1337/superadmin#/publisher/39/details
,其中39是我選擇的發佈者的ID。
問題是,如果我刷新此頁面或嘗試通過將URL從應用程序的其他區域粘貼到瀏覽器中直接導航到該頁面,我總是會回到select-publisher
狀態。我希望能夠配置我的狀態,以便能夠根據URL導航到詳細信息狀態(或任何其他狀態)。
值得注意的是,我有一個抓到底我的狀態定義的所有路徑:
$urlRouterProvider.otherwise('/select-publisher');
我假設,由於某種原因,這是被觸發,但我不能理由爲何導航在我的應用程序中使用$state.go
,正如我在控制器中指出的那樣,並且在我的HTML模板中使用ui-sref directive
,但不能直接導航到URL。
什麼是您的完整的URL是什麼樣子? – 2015-02-07 17:01:32
它已經發布在問題 – 2015-02-07 17:06:43
也許是因爲缺少斜線'url:'/ publisher/{id:int}''? – lujcon 2015-02-07 17:45:43