2017-01-03 122 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

不适合我,你可以详细解释??我做了如上所述的相同,但没有奏效..! –