2

问题是:当 url 是www.some.com时我无法访问主页,但当它是www.some.com/#!或时可以www.some.com/#!/

我定义了默认的网络应用程序路由:

$routeProvider.when('', {templateUrl: pathToIncs + 'home.html', controller: 'homeController'});
$routeProvider.when('/', {templateUrl: pathToIncs + 'home.html', controller: 'homeController'});

添加了其他选项:

$routeProvider.otherwise({redirectTo: '/404'});

并开启html5模式

$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');

正如我之前所说 - 当我像www.some.com/# 这样的 ulr 来时,它会起作用!但不是当www.some.com。在这种情况下,将调用.otherwise选项。

在任何其他情况下,路由都运行良好。在我的应用程序中,我得到了一个网址,例如 www.some.com/#!/login、www.some.com/#!/signup

PS 服务器端适用于 php5+nginx PPS 我使用 Angular 1.2.0 和 ngRoute 模块

4

1 回答 1

2

尝试设置 <base> 标签。

<head>
  <base href="/">
</head>

为家定义路线

.when('/home', {
        templateUrl: pathToIncs + 'home.html', 
        controller: 'homeController'
 })

在“/”上使用redirectTo

.when('/', {
    redirectTo: '/home'
})

连同 .otherwise

.otherwise({
    redirectTo: '/home'
});
于 2015-11-08T04:55:44.393 回答