所以我是Angular的新手,并试图弄清楚多个路由如何导致相同的视图/ templateUrl和控制器。这是我写的东西:
angular
.module('mwsApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ui.bootstrap'
])
.config(function ($routeProvider, $locationProvider) {
// debugger
$routeProvider
.when('/', {
templateUrl: 'index.html',
controller: 'MainCtrl as vm',
})
.when('/rika', {
templateUrl: 'index.html',
controller: 'MainCtrl as vm',
})
// .otherwise({
// redirectTo: '/'
// });
$locationProvider.html5Mode(true).hashPrefix("!");
});
问题:目前,如果我去为“localhost:9000 /”它让我看到了正确的版本,但如果我去为“localhost:9000 /梨花”它给我“无法得到/ rika”。
调试:我已经将问题缩小到html5Mode。我试图摆脱#! Angular会自动添加到URL上,但是当我这样做时,会弹出错误消息。
欣赏任何人的输入!
你不能摆脱的地址散列,这与使用Angular(也AJAX'ing)等路由失败的目的... –
是的,你可以,我没有摆弄它个人,但它可能 – user7951676
看看[这个SO](https://stackoverflow.com/questions/28629774/how-to-remove-the-hash- from-the-angularjs-ng-route) – Jax