Javascript 无哈希多变量Angularjs路由
大家好 我搜索了如何从路由源中删除哈希:但遇到了一个问题 我会解释的Javascript 无哈希多变量Angularjs路由,javascript,angularjs,hash,http-status-code-404,angularjs-routing,Javascript,Angularjs,Hash,Http Status Code 404,Angularjs Routing,大家好 我搜索了如何从路由源中删除哈希:但遇到了一个问题 我会解释的 $locationProvider.html5Mode(true); $routeProvider .when('/test', { controller: TestCtrl, templateUrl: 'test.html' }) .when ('/test/:idPage', { controller: PageCtrl, templateUrl: 'page.html' }) .otherwise({ r
$locationProvider.html5Mode(true);
$routeProvider
.when('/test', {
controller: TestCtrl,
templateUrl: 'test.html'
})
.when ('/test/:idPage', {
controller: PageCtrl,
templateUrl: 'page.html'
})
.otherwise({ redirectTo: '/test' });
第一次重定向
-我有类似的东西:www.my-website.com/test
一切正常。
第二项:
-www.my-website.com/test/hello
这里有一个问题,当我在路由中放置多个/时,没有加载页面,我有两个
未能加载资源:服务器以404状态响应
找不到
在我的控制台里。
一个叫:www.my-website.com/test/page.html,另一个叫:www.my-website.com/test/hello
希望有人能帮助我。提前感谢。Angular 1.4.x要求模块中包含“ngRoute”以使用$routeProvider和$locationProvider,因此将其作为: 角度路由器。 我想你会看到这样的情况: 要将其包含在模块中,请执行以下操作:
var app = angular.module('someModule', ['ngRoute']);
控制器需要在控制器中加引号:“someCtrl”如:
下面是我总结的一个例子:
$locationProvider.html5Mode(true);
$routeProvider
.when('/test', {
controller: 'TestCtrl',
templateUrl: 'test.html'
})
.when ('/test/:idPage', {
controller: 'PageCtrl',
templateUrl: 'page.html'
})
.otherwise({ redirectTo: '/test' });
var app = angular.module('plunker', ['ngRoute']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/hello/:idHere', {
templateUrl: 'resolveView.html',
controller: 'helloCtrl',
resolve: {
exclamVal: function(){
return '!!!!!!!!!!'
}
}
})
.when('/default', {
templateUrl: 'default.html',
controller: 'defaultCtrl'
})
.when('/test', {
controller: 'testCtrl',
templateUrl: 'test.html'
})
.otherwise({ redirectTo: '/default' });
$locationProvider.html5Mode(true);
}]);
app.controller('MainCtrl', function($scope, $location, $routeParams) {
});
app.controller('testCtrl', function($scope, $routeParams) {
console.log('hi')
});
app.controller('defaultCtrl', function($scope, $routeParams) {
console.log('Inside defaultCtrl')
});
app.controller('helloCtrl', function($scope, exclamVal, $routeParams) {
$scope.exclamVal = exclamVal;
$scope.myVar = $routeParams.idHere;
});