大佬教程收集整理的这篇文章主要介绍了angularjs – 带有快速的Angular HTML5模式,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的快递app.js:
var express = require('express'); var path = require('path'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); require('./routes/api')(app); var app = express(); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname,'../client'))); // This covers serving up the index page app.use(express.static(path.join(__dirname,'../client/.tmp'))); app.use(express.static(path.join(__dirname,'../client/app'))); app.all('*',function(req,res) { res.redirect('/index.html'); }); module.exports = app;
这是有角度的app.js
angular .module('punyioApp',[ 'ngAnimate','ngAria','ngCookies','ngmessages','ngresource','ngRoute','ngSanitize','ngTouch' ]) .config(function ($routeProvider,$LOCATIOnProvider) { $routeProvider .when('/',{ templateUrl: 'views/main.html',controller: 'MainCtrl',controllerAs: 'main' }) .when('/howitworks',{ templateUrl: 'views/howitworks.html',controller: 'HowItWorksCtrl',controllerAs: 'howitworks' }) .otherwise({ redirectTo: '/' }); $LOCATIOnProvider.html5Mode(true); });
现在,如果我转到http://localhost:3000/,我会按预期获得主要的Angular视图.问题是当我转到http://localhost:3000/howitworks,它将我重定向到http://localhost:3000/index.html并且没有显示’howitworks’视图.如何修复快速路由器以便我可以转到http://localhost:3000/howitworks?
基本上,你不应该使用重定向,而是sendFile:
app.get('/*',res) { res.sendFile(__dirname + '/index.html') });
以上是大佬教程为你收集整理的angularjs – 带有快速的Angular HTML5模式全部内容,希望文章能够帮你解决angularjs – 带有快速的Angular HTML5模式所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。