2017-04-24 50 views
1

我使用角度種子模板作爲我的項目。我試圖做沒有散列的路由。我在我的app.js $locationProvider.html5Mode(true);和我的index.html頭部<base href="/">中添加了,但當我刷新頁面或輸入url時,結果是我的文件夾的索引。 index of view在網址中沒有哈希的角度路由

我在做什麼錯?

+0

你使用express.js嗎? –

+0

不,它只是角種子起動器的網絡包https://github.com/angular/angular-seed – aks

回答

0

正在處理您的網頁,就好像它是服務器資源一樣,通常它會使用重寫或路徑爲每個網址提供您的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 
+0

仍然不工作,我有這個輸出 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

+0

Ops,我的不好,我忘了添加一個正確的主機名,改成'「start」:「superstatic --config superstatic.json --port 8080 --host localhost「' –

+0

確定它現在有效,但我的文件裏ke css是無法訪問的,我有意想不到的令牌<在js文件中 – aks