我知道这个问题有答案,但他们并没有完全为我工作.我正在使用Angular 1.4和Express 4. Express正在处理API调用,Angular应该处理所有
HTML.
原文链接:https://www.f2er.com/angularjs/142430.html我的快递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?