2017-01-22 123 views
-1

請幫我設置路由角度...設置角度的路由

當沒有$ location.path()index.html和MainController必須加載。 當$ location.path()= @ *時,其中*任何對象的名稱都必須加載index2.html和myController。

現在它不工作:

app.config(function ($routeProvider) { 
    $routeProvider 
     .when("/", { 
      templateUrl: "index.html", 
      controller: "MainController" 
     }) 
     .when("/@*", { 
      templateUrl: "index2.html", 
      controller: "myController" 
     }); 
}); 

回答

0

如果他們是你的只有兩條路,你可以使用otherwise(params):將在航線 變化時,可以使用

集路由定義沒有其他路由定義匹配。

app.config(function ($routeProvider) { 
    $routeProvider 
     .when("/", { 
      templateUrl: "index.html", 
      controller: "MainController" 
     }) 
     .otherwise({ 
      templateUrl: "index2.html", 
      controller: "myController" 
     }); 
}); 
+0

當我試圖直接打開'url.com/@ object' ...有 「不能GET/@對象」,我究竟做錯了什麼? – Daryushka

+0

正確我看,問題是你不是URL編碼的字符串。你不能在URL中使用'@'。如果需要的話,你必須按照[這裏](http://www.w3schools.com/tags/ref_urlencode.asp)的解釋將它編碼爲「%40」 –