在angular.js中使用ui-router的简单url



我用angular.js做了一个简单的单页应用。使用ui-router

输出url:

example.com/index.html#/profile

但是我想要这样:

example.com/profile

我该如何解决这个问题?


添加简单路由器代码

app.config(['$stateProvider', function($stateProvider) {
    $stateProvider.state('profile', {
        url: "/profile",
        templateUrl: "views/profile.html",
        controller: "ProfileCtrl",
        resolve: {
            deps: ['$ocLazyLoad', function($ocLazyLoad) {
                return $ocLazyLoad.load({
                    name: 'app',
                    insertBefore: '#ng_load_plugins_before', // load the above css files before '#ng_load_plugins_before'
                    files: [
                        'controllers/profile.js'
                    ]
                });
            }]
        }
    });
}]);

在app.js中设置Html5模式为true

locationProvider.html5Mode美元(真正);

最新更新