简体   繁体   English

当我在浏览器中刷新页面时,路由在我的Web应用程序中不起作用

[英]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.

相关问题 刷新Web浏览器时Firebase数据不起作用 - Firebase data not working when refresh web browser Rails Controller - 刷新页面就像我在浏览器上点击刷新一样 - Rails Controller - refresh page same as if I hit the refresh on my browser ReactApp-当我在VS代码编辑器中将js文件中的更改保存时,浏览器不会刷新页面。 - ReactApp - The browser does not refresh the page when i save changes in my js file in VS code editor . 当我使用反应路由重新加载具体页面时,我的应用程序崩溃了 - My application breaks down when I reload the concrete page using react routing 在VI中保存文件后如何刷新Web浏览器 - How to refresh my web browser after I save a file in VI 当我刷新页面时 JavaScript 停止工作 - JavaScript stops working when I refresh page Angular 2路由无法在页面刷新或使用gulp重新加载? - Angular 2 routing not working on page refresh or reload with gulp? 我的反应代码正在工作,但是当我刷新页面时,我得到 TypeError: Cannot read property 'Location' of undefined - my react code is working but when i refresh the page i get TypeError: Cannot read property 'Location' of undefined 浏览器页面刷新后,Angular js无法路由到默认页面 - Angular js not routing to default page after browser page refresh 刷新客户端网页时如何重新连接到Web套接字 - How to reconnect to a Web Socket when I refresh the client web page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM