我是新來角。我創建了一個展示我的個人資料的博客。 在我的網站,我有幾個分量和我app.module具有路由的配置,如圖所示:如何正確使用Angular 1.5進行SPA的路由?
app.config(function($locationProvider, $routeProvider){
$locationProvider.html5Mode({
enabled:true,
requireBase: false
})
$routeProvider.
when("/", {
template: "<research-overview></research-overview>"
}).
when("/research-interests", {
template: "<research-interests></research-interests>"
}).
otherwise({
redirectTo: "/"
})
});
這裏是我的組件的例子:
angular.module('researchOverview', [])
.component('researchOverview', {
templateUrl: '/templates/research-overview.html',
});
我試圖在本地使用python -m SimpleHttpServer
運行服務器,以便我可以使用瀏覽器訪問我的本地網站localhost:8000
,當我點擊我主頁上的鏈接時,該頁面已正確加載。但是,當我最初使用不同的網址訪問我的網站時(例如localhost:8000/testing
),角度路線似乎無法正常工作。 我得到這個錯誤,而不是,
如何設置路由器,使這些URL可以被重定向到我的主頁?
你不能在Python中使用帶'SimpleHttpServer'的'html5Mode',而無需爲它編寫自己的子類,例如。 https://gist.github.com/RyanBalfanz/ee579e5dec2d843acff1646943d7e96b – Claies
啊!問題在於simpleHttpServer?感謝這 –
如果你想展示這樣的網址,你應該使用「真實」的網址,以便用戶可以收藏和恢復標籤;這意味着你需要在每個地點給出一個url的實際頁面。它可能是一個常見的錯誤頁面,或者您可以使用服務器來服務實際的最終內容,從而提高搜索引擎優化。 – dandavis