【发布时间】:2017-12-08 10:08:03
【问题描述】:
我正在尝试使用 Angular 中的 UI-Route 进行简单的路由,但是当我在浏览器中输入带有 # 的 url 时,就像这样 http://localhost:8080/#/stateone 它会添加一些奇怪的符号,比如 http://localhost:8080/#!#%2Fstateone。谁能解释一下这是怎么回事?
这是我在 app.js 文件中的代码:
angular
.module('myApp', ["ngMaterial", "ui.router"])
.config(function($mdThemingProvider, $stateProvider) {
$mdThemingProvider.theme('default')
.primaryPalette('teal')
.accentPalette('orange');
$stateProvider
.state('stateone' , {
url: '/stateone',
template: '<h1>State One</h1>'
})
.state('statetwo', {
url: '/statetwo',
template: '<h1>State Two</h1>'
});
});
模板的文件代码:
<ui-view></ui-view>
【问题讨论】:
-
你的 hash-bang 是
#!,所以通过引入#/stateone它使它成为#!#/stateone,它被 URL 编码成#!#%2Fstateone
标签: angularjs