Angular-ui-router不支持外部URL,您需要使用
$location.url()或重定向用户
$window.open()
我建议您使用
$window.open('http://www.google.com', '_self')它将在同一页面上打开URL。
更新资料
您还可以
ui-router通过添加参数来自定义
external,它可以是
true/
false。
$stateProvider .state('external', { url: 'http://www.google.com', external: true })
然后
$stateChangeStart在您的状态中配置并在那里处理重定向部分。
运行块
myapp.run(function($rootScope, $window) { $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { if (toState.external) { event.preventDefault(); $window.open(toState.url, '_self'); } });})
plnkr
注意 :为了使它能正常工作, 请 在新窗口中打开Plunkr,因为出于安全原因,
Google 无法在iframe中打开它。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)