【问题标题】:ngRoute not working when refreshing the page刷新页面时ngRoute不起作用
【发布时间】:2015-02-16 14:41:06
【问题描述】:

该网站在http://www.athimannil.com/ 上使用ngRoute 工作正常,但不幸的是页面http://www.athimannil.com/about 在刷新URL 时无法正常工作:(

是否需要在 JavaScript 代码中添加任何额外内容?

var app = angular.module('app',['ngRoute']);
    app.config(function($routeProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $routeProvider
            .when('/', {
                templateUrl: 'home.html',
                controller: 'homecontroller'
            })
            .when('/about', {
                templateUrl: 'about.html',
                controller: 'aboutController'
            })
            .when('/portfolio', {
                templateUrl: 'portfolio.html',
                controller: 'portfolioController'
            })
            .when('/contact', {
                templateUrl: 'contact.html',
                controller: 'contactController'
            })
            .when('/cv', {
                templateUrl: 'cv.html',
                controller: 'cvController'
            })
            .otherwise({
                redirectTo: '/'
            });
    });

.htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

【问题讨论】:

  • 这是由于 html5mode 的复杂性,请在此处查看:stackoverflow.com/questions/19211576/…
  • 如果您将about.html 放在像/partials/about.html 这样的目录中可能会有所帮助。
  • @Dylan 刚刚进行了您提到的更改。仍然发生同样的错误:/

标签: javascript angularjs angularjs-routing ng-view angularjs-ng-route


【解决方案1】:

默认情况下,Angular 使用 .../#/... 之类的路由

如果你想删除你需要一些服务器配置

AngularJS routing without the hash '#'

【讨论】:

    猜你喜欢
    • 2017-11-11
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 2016-08-07
    • 2023-03-26
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多