gpt4 book ai didi

javascript - Angular .JS : cannot set default route when no hash

转载 作者:行者123 更新时间:2023-11-29 22:07:50 24 4
gpt4 key购买 nike

问题是:当 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

附言服务器端适用于 php5+nginx附言我将 Angular 1.2.0 与 ngRoute 模块一起使用

最佳答案

尝试设置 标签。

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

定义回家的路线

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

在“/”上使用 redirectTo

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

连同.otherwise

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

关于javascript - Angular .JS : cannot set default route when no hash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19944657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com