javascript - 从 angularJS $stateProvider 获取 URL 中的 #

标签 javascript angularjs url-routing angularjs-routing

我的网址中间出现一个奇怪的#,例如,如果我尝试访问 localhost:8080,我的 AngularJS 应用程序正在运行,我会被重定向到 http://localhost:8080/#/home 。我不明白这个 # 来自哪里,但我怀疑它与我在 $stateProvider 中定义的 URL 有关。

这是 $stateProvider 代码:

//STATE HANDLER
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
app.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {

    $stateProvider
        .state('newAlarm', {
            url: '/newAlarm',
            views: {
                '': {templateUrl: '/templates/newAlarmPage.html'},
                'header@newAlarm':{templateUrl: '/templates/header.html'},
                'newAlarmForm@newAlarm':{templateUrl: '/templates/newAlarmForm.html'}
            },
            controller: 'NewScheduleCtrl'
        })

        //to be changed
        .state('home', {
            url: '/home',
            views: {
                '': {templateUrl: '/templates/homePage.html'},
                'header@home':{templateUrl: '/templates/header.html'}
            },
            controller: ''
        });
    //end of to be changed
    $urlRouterProvider.otherwise('home');
}]);

有什么想法吗?

最佳答案

摘自维基百科文章single page applications :

The page does not reload at any point in the process, nor does control transfer to another page, although the location hash can be used to provide the perception and navigability of separate logical pages in the application

使用哈希使 Angular(和其他 SPA 框架)能够路由 URL,而无需重新加载页面。

相关问题:

关于javascript - 从 angularJS $stateProvider 获取 URL 中的 #,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35043399/

相关文章:

java - 如何克服 Angular JS 的 CORS 问题

angularjs - 如何从 Angular 资源 $save() 读取响应并保留原始数据

php - Zend Framework 中数据库驱动路由的教程?

javascript - 如何在 js 中从 php 动态获取值?

c# - 使用 ScriptManager.RegisterClientScriptIninclude 注册 JavaScript 文件

javascript - 如何防止 iframe 自身统一框架

javascript - 在模板中非法使用 ng-Transclude 指令

angularjs - 在 AngularJS 中不使用时如何从范围中删除?

javascript - url 路由中的 ":op?"是什么意思?

php - 将 URL 路由转换为函数参数 php mvc