[英]Route “ui-route” not working. TemplateUrl html not visible in ui-view
我使用ui-router angular js文件進行路由,在復雜情況下使用時不起作用。 我已將所有代碼發布在Plunker中,以供您查看,並在此先感謝您的時間和幫助。
"use strict";
var app = angular.module( "productManagement", ["ui.router", "common.services", "productResourceMock"] );
app.config([ "$stateProvider", "$urlRouterProvider",
function($stateProvider, $urlRouterProvider){
// Redirect to home view when route not found
$urlRouterProvider.otherwise("/");
$stateProvider
// Home state routing
.state("home", {
url: "/",
templateUrl: "route-welcome.html"
})
.state("productList", {
url: "/products",
templateUrl: "route-productlist.html"
})
.state("productDetail", {
url: "/products/detail/:productId",
templateUrl: "route-productdetail.html"
})
}
]);
$httpBackend
捕獲了您對模板頁面的請求,該文件不了解您的.html
文件。 相反,它引發如下錯誤:
錯誤:意外請求:GET route-welcome.html
預計沒有其他要求
要解決此問題,您可以將passThrough
添加到您的app.run
:
....
$httpBackend.whenGET(productUrl).respond(products);
$httpBackend.whenGET(/\.html$/).passThrough();
....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.