我正在开发angularjs和PHP的博客。使用nodejs一切都很完美,我可以使用“stateProvider”来路由应用程序。现在我正在使用xampp但是当我在url中插入“localhost / home / content”类型的地址告诉我“找不到对象”时,好像实际上要在服务器上查找对象而不是使用路由功能angularjs。如果我插入“localhost / index_2.html”,它实际上正确地向我显示页面,并且url变为“localhost / home / content”(正如我所期望的那样)。我该如何解决?谢谢!
app.js
var importPath = "/partial/";
var home = importPath+"home/";
var homeContainer = home + 'homeContainer.html';
var homeContent = home + 'homeContent.html';
app.config(
["$stateProvider", "$urlRouterProvider", "$locationProvider",
function($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('home', {
templateUrl: homeContainer,
})
.state('home.homeContent', {
url: '/home/content',
templateUrl: homeContent,
});
$urlRouterProvider.otherwise("/home/content");
$locationProvider.html5Mode(true);
}
]);
app.run(['$rootScope', '$location',
function ($rootScope, $location)
{
console.log("location ", $location.path());
}
]);
index_2.html
......
<body>
...
<div ui-view></div>
...
</body>
答案 0 :(得分:0)
根据收到的评论,我能够通过删除index.html文件中的html5模式和标记<base href="/">
来解决问题。
现在基本网址为http: // localhost / #! / Home / content