2016-08-13 102 views
1

我設法通過將locationProvider.html5Mode設置爲true從我的網址中刪除了散列#,但出現了另一個問題。沒有顯示,並在我的控制檯上給我一個404錯誤Angular js 1,路由,locationProvider,404錯誤

我很清楚,這個問題已經有好幾次了,但我已經嘗試過所有這些解決方案,但都沒有成功。請協助。

var app = angular.module('app', ['ngRoute']); 

app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { 
    $locationProvider.html5Mode(true); 
    $routeProvider 
    .when('/', { 
     templateUrl: 'home.html', 
     //controller:'homecontroller' 
    }) 
    .when('/home', { 
     templateUrl: 'home.html', 
     //controller:'homecontroller' 
    }) 
    .when('/best-prices-buy-phones-in-kenya', { 
     templateUrl: 'pages/buy-phones.html', 
     //controller:'aboutcontroller' 
    }) 
    .when('/best-prices-buy-phones-in-kenya2', { 
     templateUrl: 'pages/buy-phones-htc.html', 
     //controller:'servicecontroller' 
    }) 
    .when('/contact_us', { 
     templateUrl: 'contact-page.html', 
     //controller:'contactcontroller' 

    }); 
}]); 
+0

表明你的觀點! – Sajeetharan

+0

你好。 @Sajeetharan請在https://plnkr.co/edit/bB2pSplv3dRdGlDE9Rv2?p=preview plunker找到 –

回答

0

index.html中,您不再需要的是 '#' '$ locationProvider.html5Mode(真);'照顧這個。所以鏈接上的href應該只是一個'/'加上你需要的頁面,例如

<a href='/home'> 

<a href='/best-prices-buy-phones-in-kenya'>