簡體   English   中英

AngularJs UI路由器自定義URL

[英]AngularJs ui-router custom url

好的,這是問題所在。 我有一個應用程序,用戶可以在該應用程序中注冊為商人,並可以擁有自己的商店名稱,而我要查找的網址是:

http://localhost:8000/#/storename 

這與默認的主頁子頁面(例如contactus, aboutus發生沖突。 以下是我對ui-router

.state('home', {
            url: '/', --> http://localhost:8000/#/ [work]
            templateUrl: 'views/main_home.html',
            resolve: loadSequence('flexSlider','wantCtrl'),
            css: 'assets/vendor/style.css'
          })
      .state('home.contact', {
            url: '/contact', --> http://localhost:8000/#/contact [not work]
            views: {
                    'homeView': {
                        templateUrl: 'partials/contact.html',

                    }
                },
            css: ['assets/vendor/style.css']
          })
           .state('store',{
            url: '/:storename',  -->  http://localhost:8000/#/myshop [work]
                templateUrl: 'views/main_store.html'        
            })
         .state('store.list', {
            url: '/lists', -->  http://localhost:8000/#/myshop/lists [work]
                views: {
                    'primView': {
                        templateUrl: 'views/store_home.html',
                    }
                }   
            })

這里http://localhost:8000/#/contact正在訪問store模板,就好像contact是商店名稱一樣。 默認任何繼承home.[anything]應該在父級定義的模板下。 我該如何解決這個問題?

這樣做有一種骯臟的方式,即為每個子頁面定義新的父級,但這將是頁眉和頁腳部分布局的重復。

據我所知,在處理路線時,角度遵循自上而下的方法。 所以定義

       .state('store',{
        url: '/:storename',  -->  http://localhost:8000/#/myshop [work]
            templateUrl: 'views/main_store.html'        
        })

在所有其他路線之后。 在您的情況下,當angular到達/:storename時,它將認為聯系人是商店名稱,並加載該頁面。 為了避免它,你需要保持最后

暫無
暫無

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

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