Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – Nodejs&Angularjs,Clean urls大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何设置node / angular以使index.html / app在example.com而不是example.com/app/index.html#/home上运行

我尝试将index.html放在节点服务器的根目录下,但仍保留url作为example.com/index.html#/home

解决方法

你需要的是启用 @L_687_1@mode.它的文档和注意事项可以在 here找到.

以下是从Brian Ford开始的示例:

angular.module('myApp',['myApp.filters','myApp.services','myApp.directives']).
  config(['$routeProvider','$LOCATIOnProvider',function($routeProvider,$LOCATIOnProvider) {
    // configure $routeProvider,then...
    $LOCATIOnProvider.html5Mode(true);
  }
]);

angular-ui框架有example configuration用于连接到express.js:

var express = require('express');
var app = express();

app.use('/js',express.static(__dirname + '/js'));
app.use('/dist',express.static(__dirname + '/../dist'));
app.use('/css',express.static(__dirname + '/css'));
app.use('/partials',express.static(__dirname + '/partials'));

app.all('/*',function(req,res,next) {
    // Just send the index.html for other files to support HTML5Mode
    res.sendfile('index.html',{ root: __dirname });
});

app.listen(3006); //the port you want to use

在Brian的文章中,您不必手动映射静态资产文件夹,因为他的示例提供单个index.html,将partials映射到/ partials /:name,然后与/ api / *交互

大佬总结

以上是大佬教程为你收集整理的node.js – Nodejs&Angularjs,Clean urls全部内容,希望文章能够帮你解决node.js – Nodejs&Angularjs,Clean urls所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。