首页 > 代码库 > angular 路由去除#号
angular 路由去除#号
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="http://www.mamicode.com/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 就是前端路由了
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。