1. 路由启动 $locationProvider.html5Mode(true);
app.js
define([
‘angular‘,
"App/Ctrl/controllers",
"App/Directive/directive",
"angularRoute"
], function (angular,controllers,directives,appDirec) {
var app=angular.module(‘myApp‘, ["ngRoute",controllers.name,directives.name])
templete="/front/propertyEntrust/view/templete"
/* /limitSell/add?propertyId=33 */
app.config([‘$routeProvider‘,"$locationProvider", function ($routeProvider,$locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.when(‘/detail/:Id‘, { //详情页面
templateUrl: templete+‘/detail.html‘
});
$routeProvider.when(‘/rent/add/:propertyId‘, { //一般出租
templateUrl: templete+‘/rent.html‘
});
$routeProvider.when(‘/rent/edit/:Id‘, { //一般出租
templateUrl: templete+‘/rent.html‘
});
$routeProvider.when(‘/sale/add/:propertyId‘, {
templateUrl: templete+‘/sale.html‘
});
$routeProvider.when(‘/sale/edit/:propertyId‘, {
templateUrl: templete+‘/sale.html‘
});
$routeProvider.when(‘/exclusiveRent/add/:propertyId‘, { //独家出租
templateUrl: templete+‘/exclusiveRent.html‘
});
$routeProvider.when(‘/exclusiveRent/edit/:Id‘, { //独家出租
templateUrl: templete+‘/exclusiveRent.html‘
});
$routeProvider.when(‘/exclusiveSale/add/:propertyId‘, {
templateUrl: templete+‘/exclusiveSale.html‘
});
$routeProvider.when(‘/exclusiveSale/edit/:Id‘, {
templateUrl: templete+‘/exclusiveSale.html‘
});
$routeProvider.when(‘/limitSell/add/:propertyId‘, { //签赔
templateUrl: templete+‘/limitSell.html‘
});
$routeProvider.when(‘/limitSell/edit/:Id‘, { //签赔
templateUrl: templete+‘/limitSell.html‘
});
$routeProvider.when(‘/err/:propertyId‘, {
templateUrl: templete+‘/err.html‘
});
$routeProvider.otherwise({redirectTo: ‘/rent‘});
}]);
return app
});
2. 设置前端路由开始的字段 即服务器路由的最后的字段
<base href="/index/">
3, 服务器配置 nodejs为例
app.get(‘/fy/propertyEntrustApply/index/*‘, function (req, res) {
res.render("a", {});
});
/*app.get(‘/property/:id(\\d+)‘, function (req, res) {
res.render("b",{});
});*/
app.get(‘/property/:id‘, function (req, res) {
res.render("b", {});
});
app.get(‘/qmTable‘, function (req, res) {
res.render("c", {});
});
如上所示 http://localhost:3000/fy/propertyEntrustApply/index/rent/add/21
/fy/propertyEntrustApply/index/ 为服务器路由 指向a.ejs
之后/rent/add/21 就是前端路由了
原文:http://www.cnblogs.com/breakdown/p/3785773.html