在网址中没有哈希的角度路由
我使用角度种子模板作为我的项目。我试图做没有散列的路由。我在我的app.js $locationProvider.html5Mode(true);
和我的index.html头部<base href="/">
中添加了,但当我刷新页面或输入url时,结果是我的文件夹的索引。 在网址中没有哈希的角度路由
我在做什么错?
正在处理您的网页,就好像它是服务器资源一样,通常它会使用重写或路径为每个网址提供您的index.html文件(或默认输入)。
你可以使用不同的服务器来做到这一点,我采用了superstatic
npm包,它提供了url重写,而不是存在于angularjs-seed项目中的http-server
。
npm install superstatic --save-dev
与以下内容您的应用程序的根目录下创建文件superstatic.json
:
{
"cleanUrls": true,
"rewrites": [
{"source":"/**","destination":"/app/index.html"}
]
}
,并覆盖以下行的文件中package.json
"scripts": {
...
"start": "http-server -a localhost -p 8000 -c-1 ./app",
...
}
要
"scripts": {
...
"start": "superstatic --config superstatic.json --port 8080 --host localhost",
...
}
最后
npm start
仍然不工作,我有这个输出 dns.js:112 throw new TypeError('Invalid arguments:' + ^ 类型错误:无效参数:主机名必须在Object.lookup字符串或falsey (dns.js:112:11) 在listenAfterLookup(net.js:1403:20) 在Server.listen(净.js:1399:5) at Function.listen ... – aks
Ops,我的不好,我忘了添加一个正确的主机名,改成'“start”:“superstatic --config superstatic.json --port 8080 --host localhost“' –
确定它现在有效,但我的文件里ke css是无法访问的,我有意想不到的令牌 aks
你使用express.js吗? –
不,它只是角种子起动器的网络包https://github.com/angular/angular-seed – aks