簡體   English   中英

我可以在hrefRouterProvider中使用href嗎?

[英]Can I use href with urlRouterProvider?

在我的angularjs應用程序中,我已用ui.router(urlRouterProvider)模塊和stateProvider替換了ngRoute(routeProvider),並在應用程序的狀態之間進行導航。

現在,我發現ui-router僅適用於狀態和<a ui-sref="">而不是<a href=""> 由於必須使用javascript在應用程序外部設置應用程序導航,因此無法將錨點從href更改為sref。 這是我設置導航鏈接的方法。

    Portal.setNavigation(
        [
            {
                "label": "Application1",
                "selected": true,
                "url": "/web/guest#/Application1"
            }
        ]
    );

該代碼集相應地具有href屬性。 這是我的stateProvider代碼段,它適用於像這樣的手動放置的sref<a ui-sref="Application1">Application State 1</a>

app.config(['$stateProvider', '$urlRouterProvider',
  function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('Application1', {
            url: '/Application1',
            templateUrl: '/Application.html',
            controller: 'AppCtrl'
        });
}]);

有什么想法可以繼續使用ui-router和使用href導航狀態嗎?

如果您通過執行諸如window.location(url)之類的操作來通過javascript導航到應用程序之外,則應該能夠將您所在州的路由放入url中,並且路由器應該能夠處理該路由,即window.location(/ state1)。

這是ui-router的文本,它對此有所啟發( link ):

這是設置基本網址的方法。

 $stateProvider .state('contacts', { url: "/contacts", templateUrl: 'contacts.html' }) 

現在,當用戶訪問index.html / contacts時,“ contacts”狀態將變為活動狀態,並且主用戶界面視圖將填充“ contacts.html”部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM