gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 15:07:11 24 4
gpt4 key购买 nike

我的网址中间出现一个奇怪的#,例如,如果我尝试访问 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com