[英]Routing is not working in my web application when I refresh the page in the browser
When I type http://localhost:8000 in the browser, it is redirecting to http://localhost:8000/home . 当我在浏览器中输入http:// localhost:8000时,它将重定向到http:// localhost:8000 / home 。 This is working fine as per code.
按照代码,这工作正常。 When I refresh the page with same http://localhost:8000/home getting 404 error.
当我使用相同的http:// localhost:8000 / home刷新页面时,出现404错误。 Can anyone help me why this is happening and correct me.
谁能帮助我为什么会这样并纠正我。
app.js app.js
var myapp=angular
.module("demo",['ngRoute'])
.config(function ($routeProvider, $locationProvider){
$routeProvider
.when('/home',{
templateUrl:'Templates/home.html',
controller:'homeController'
})
.when('/about', {
templateUrl:'Templates/about.html',
controller:'aboutController'
})
.when('/contact',{
templateUrl:'Templates/contact.html',
controller:'contactController'
})
.otherwise({
redirectTo: '/home'
})
$locationProvider.html5Mode(true);
});
index.html index.html
<!doctype html>
<html lang="en" ng-app="demo">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="rest-controller.component.js"></script>
<script src="Controllers/contact.js"></script>
<script src="Controllers/about.js"></script>
<script src="Controllers/home.js"></script>
<base href="/">
</head>
<body>
<ol>
<li><a href="home">Home</a></li>
<li><a href="about">About</a></li>
<li><a href="contact">Contact</a></li>
</ol>
<div ng-view></div>
</body>
</html>
home.js (controller file) home.js(控制器文件)
angular.module('demo').controller("homeController", function($scope){
$scope.hello ="home";
});
about.js about.js
angular.module('demo').controller("aboutController", function($scope){
$scope.tap="About Me";
});
contact.js contact.js
angular.module('demo').controller("contactController", function($scope){
$scope.message="hello";
});
您可以尝试禁用html5模式吗?
// $locationProvider.html5Mode(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.