2017-01-03 117 views
-1

我面臨着「#」符號的問題。我想從我的角色js網站的URL中刪除#。我試圖通過「提供的鏈接」的幫助刪除它,但它不工作,該網站不顯示任何內容。請讓我知道如何使它成爲可能。如何從URL中刪除#符號。從角度js中的url中刪除#符號

這裏是我的route.js代碼: -

var app = angular.module("myApp", ["ngRoute"]); 
app.config(function($routeProvider) { 
    $routeProvider 
    .when("/", { 
     templateUrl: 'Templates/home.html', 
    }) 
    .when("/first", { 
     templateUrl: 'Templates/first.html', 
    }) 
    .when("/second", { 
     templateUrl: 'Templates/second.html', 
    }) 
    .when("/third", { 
     templateUrl: 'Templates/third.html', 
    }) 
    .when("/admin", { 
     templateUrl: 'Templates/admin.html', 
    }) 
    .otherwise({ 
     redirectTo: '/' 
    }); 
+0

你試圖刪除'#'。說明。 – SaiUnique

回答

0

您可以使用$locationProvider

var app = angular.module("myApp", ["ngRoute"]); 
    app.config(function($routeProvider, $locationProvider) { 
     $routeProvider 
     .when("/", { 
      templateUrl: 'Templates/home.html', 
     }) 
     .when("/first", { 
      templateUrl: 'Templates/first.html', 
     }) 
     .when("/second", { 
      templateUrl: 'Templates/second.html', 
     }) 
     .when("/third", { 
      templateUrl: 'Templates/third.html', 
     }) 
     .when("/admin", { 
      templateUrl: 'Templates/admin.html', 
     }) 
     .otherwise({ 
      redirectTo: '/' 
     }); 
      $locationProvider.html5Mode({ 
      enabled: true, 
      requireBase: false 
     }); 
0

使用HTML5歷史API

$locationProvider.html5Mode(true); 

或者,你可以使用base index在你的index.html(我想這是你的着陸頁)

<head> 
    <base href="/"> 
</head> 

更多詳細信息,請訪問:https://scotch.io/tutorials/pretty-urls-in-angularjs-removing-the-hashtag

+0

它不適合我。在我寫在這裏之前,我嘗試了它。我是Angular js的新手,所以我不知道我要去哪裏錯了。 –

0

在app.js

var app = angular.module("myApp", ["ngRoute"]); 
app.config('$routerProvider', '$locationProvider',function($routeProvider,$locationProvider) { 

    $locationProvider.html5Mode(true).hashPrefix('*'); 

    $routeProvider 
    .when("/", { 
     templateUrl: 'Templates/home.html', 
    }) 
    .when("/first", { 
     templateUrl: 'Templates/first.html', 
    }) 
    .when("/second", { 
     templateUrl: 'Templates/second.html', 
    }) 
    .when("/third", { 
     templateUrl: 'Templates/third.html', 
    }) 
    .when("/admin", { 
     templateUrl: 'Templates/admin.html', 
    }) 
    .otherwise({ 
     redirectTo: '/' 
    }); 

嘗試這一點,並在你的index.html文件頭部分添加此基礎標籤

<head> 
    <base href="/"> 
</head> 
+0

不適合我,你可以詳細解釋??我做了如上所述的相同,但沒有奏效..! –