如何在AngularJS URL中的hashtag(#)前面加上字符串



是否可以在angular.js url的#符号前加上字符串?

例如:
假设我有一个网站:http://example.com/然后
当我点击CSharp页面时,它会重定向到http://example.com/#/csharp
当我点击AngularJS页面时,它会重定向到http://example.com/#/angularjs

所以我想在#前面加上字符串say"language",这样url就变成了–
当我点击CSharp页面时,它会重定向到http://example.com/language#/csharp
当我点击AngularJS页面时,它会重定向到http://example.com/language#/angularjs

我有以下给出上述输出的示例代码–

var angularApp= angular.module('MyApp', []);
angularApp.config(function ($routeProvider) {
   $routeProvider
        .when('/', {
            templateUrl : 'partials/home.html',
        })
        .when('/csharp', {
            templateUrl : 'partials/csharp.html',
        })
        .when('/angularjs', {
            templateUrl : 'partials/angularjs.html',
        });
});

您可以使用hashPrefix。示例:

$locationProvider.hashPrefix('language');

更多信息,请访问https://docs.angularjs.org/guide/$location

最新更新