2017-01-03 8 views
-1

"#"記号に問題があります。私は私の角度のjsウェブサイトのURLから#を削除したい。私は "提供されたリンク"の助けを借りてそれを削除しようとするが、それは動作していないとサイトは何も表示されません。それを可能にする方法を教えてください。 URLから#記号を削除する方法。ここで 角度jsのURLから#記号を削除

がroute.jsのための私のコードです: - あなたは

$locationProvider.html5Mode(true); 

代わりにHTML5履歴APIを使用し$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

「#」を削除しようとしました。説明する。 – SaiUnique

答えて

0

を使用することができます

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

私のために働いていません。私はここに書き込む前にそれを試しました。私はAngular jsを初めて使っているので、どこが間違っているのかわからない。 –

0

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: '/' 
    }); 

あなたapp.jsでこれを試してみて、ヘッド部にあなたのindex.htmlファイルに

をこのベースタグを追加します
<head> 
    <base href="/"> 
</head> 
+0

私のために働いていないあなたは詳細に説明できますか?私は上記と同じことをしたが、うまくいかなかった.. !! –

関連する問題