使$location.path同框打开(target = "_self")

Make $location.path open in the same frame (target = "_self")

在使用 html5 模式的平均堆栈 Web 应用程序中,我定义了以下 angular-ui-router

.state('addinHome', {
    url: '/addin/home',
    template: "home page"
})

然后,我有另一个带有按钮 <a href="/addin/home">button</a> 的页面 https://localhost:3000/test/。同样在它的控制器中,我有

... ...
$location.path("/addin/home")
... ...

通常,$location.path 和按钮都会导致 https://localhost:3000/addin/home

现在,我在 index.html 中添加以下引用:

<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script src="https://cdn.rawgit.com/devote/HTML5-History-API/master/history.js"></script>

它干扰了 ui-路由器。因此,$location.path 和按钮都会导致 https://localhost:3000/test/#%2Faddin#%2Fhome,这不是我想要的。

我找到了修复按钮的解决方案:它正在使用 <a href="addin/home" target="_self">button</a>(在单击时在同一框架中打开链接文档;请参阅 )。

但是,我还没有找到修复 $location.path("/addin/home") 的解决方案。有人可以帮忙吗?

  • 注入 $window 作为依赖。

  • 尝试使用 $window.open(URL,"_self")