问题
I am using angularjs with requirejs. I am running into a problem where my routes are not being routed properly. It's constantly routing to /. If I change /post to /:post it hits my post route.
// module/post.js
define([], function () {
'use strict';
var app = angular.module('myApp.post', [])
.config(['$routeProvider',
function($routeProvider) {
$routeProvider.when('/post', {
controller: 'PostController',
template: "<div>{{page}}</div>"
}
);
}
]);
return app;
});
// main.js
require.config({
baseUrl: '/static/js',
paths: {
angular: 'vendor/angular/angular',
jquery: 'vendor/jquery/jquery',
_: 'vendor/underscore/underscore'
},
shim: {
angular: {
exports: angular
}
}
});
require([
'module/post'
], function() {
'use strict';
var app = angular.module('myApp', [
'myApp.post'
])
.config(['$routeProvider',
function($routeProvider) {
$routeProvider.otherwise({
redirectTo: '/'
});
}
]);
$(function(){
angular.bootstrap(document, ['myApp']);
$('html').addClass('ng-app: myApp');
});
});
回答1:
Dumb mistake on my part. I'll leave this question opened in case someone runs into this problem.
I did not have html5 mode on
var app = angular.module('myApp.post', [])
.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$routeProvider.when('/post', {
controller: 'PostController',
template: "<div>{{page}}</div>"
}
);
$locationProvider.html5Mode(true);
}
]);
otherwise my urls would map with hashbang localhost/#post instead of /post
来源:https://stackoverflow.com/questions/18584703/angularjs-routeprovider-route-not-found