Pur*_*raw 9 anchor angular-ui-router
我使用了角度ui路由器,就像
.state('home', {
url: '/home',
templateUrl: 'view/home/home.html',
controller: 'homeCtrl'
})
.state('guide', {
url: '/guide',
templateUrl: 'view/guide/guide.html',
controller: 'guideCtrl'
})
Run Code Online (Sandbox Code Playgroud)
我可以在浏览器中访问一个网址,http:// localhost:8000/dist /#/ home 但是,如果home.html中有一个锚点我不能在我的html中使用锚点
<a href="#aaa">scroll to aaa</a>
....
<h1 id="aaa">AAA</h1>
Run Code Online (Sandbox Code Playgroud)
当我点击"滚动到aaa"时,网址将是http:// localhost:8000/dist /#/ aaa 并返回一个空白页面.home.html中的锚点不起作用.
我该如何解决这个问题?
确保你有一个比0.2.14更新的ui-router版本,这是第一个支持ui-router中的html锚点的版本.所有版本都可以在github上找到,我首先注意到它是受支持的.
鉴于您的路由设置:
.state('home', {
url: '/home',
templateUrl: 'view/home/home.html',
controller: 'homeCtrl'
})
.state('guide', {
url: '/guide',
templateUrl: 'view/guide/guide.html',
controller: 'guideCtrl'
})
Run Code Online (Sandbox Code Playgroud)
在任何视图上创建链接:
<a href="" ui-sref="home({'#': 'aaa'})">Scroll to AAA</a>
Run Code Online (Sandbox Code Playgroud)
在页面视图/ home/home.html
....
....
<h1 id="aaa">AAA</h1>
Run Code Online (Sandbox Code Playgroud)