Angular.JS:不能设置默认路由时,没有散 [英] Angular.JS: cannot set default route when no hash

查看:99
本文介绍了Angular.JS:不能设置默认路由时,没有散的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的问题是
当网址为我无法到达主页www.some.com ,但可以当它是www.some.com/#!或www.some.com /#!/

我定义默认的Web应用程序的路线:

  $ routeProvider.when('',{templateUrl:pathToIncs +'home.html做为',控制器:HomeController的'});
$ routeProvider.when('/',{templateUrl:pathToIncs +'home.html做为',控制器:HomeController的'});

补充否则选项:

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

和HTML5的方式反过来

  $ locationProvider.html5Mode(假);
$ locationProvider.hash preFIX(!);

正如我说befor - 它工作时,我喜欢的 www.some.com /#,但不是在 www.some.com 走过来ULR!在这种情况下的。否则选项将被调用。

在任何其他情况下的路由效果很好。在我的应用我有一个像www.some.com/#!/login一个网址,www.some.com /#!/注册

P.S。服务器端工作在PHP5 + nginx的
P.P.S.我用角1.2.0 ngRoute模块


解决方案

尝试设置的< base>标记。

 < HEAD>
  <基本href =/>
< /头>

有家庭定义的路由

 。当('/家',{
        templateUrl:pathToIncs +'home.html做为',
        控制器:HomeController的
 })

使用redirectTo的/

 。当('/',{
    redirectTo:'/家
})

随着一起。否则

 。否则({
    redirectTo:'/家
});

The problem is: I cannot reach home page when url is www.some.com but can when it's www.some.com/#! or www.some.com/#!/

I was define default web app route:

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

Added otherwise option:

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

And turn of html5 mode

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

As i said befor - it works when I'm came by ulr like www.some.com/#! but not when www.some.com. In this case .otherwise option will be called.

In any other case routing works well. In the my app I got an urls like a www.some.com/#!/login, www.some.com/#!/signup

P.S. Server side works on php5+nginx P.P.S. I'm use Angular 1.2.0 with ngRoute module

解决方案

Try setting the < base > tag.

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

Have a route defined for home

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

using redirectTo on the "/"

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

along with the .otherwise

.otherwise({
    redirectTo: '/home'
});

这篇关于Angular.JS:不能设置默认路由时,没有散的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆