角路线 - 重定向到一个外部网站? [英] Angular routes - redirecting to an external site?

查看:143
本文介绍了角路线 - 重定向到一个外部网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个AngularJS routes文件有一个,否则路由选项,替换404:

In an AngularJS routes file there is the option for an otherwise route, replacing a 404:

$routeProvider
.when(...)
.otherwise({
    redirectTo: 'my/path'
});

有没有办法做到这一点使得否则重定向到一个网页,是不是在应用程序?我试过

Is there a way to do this such that the otherwise redirects to a page that is not in the app? I tried

$routeProvider
.when(...)
.otherwise({
    redirectTo: 'http://www.mysite.com'
});

但这仅仅指刚试图重定向到我的应用程序的路径,它不存在。我知道解决的办法是做手工重定向在 $范围。$在('$ routeChangeStart')在顶层控制器,但是这是一个很多$的C $ç重复(和它的丑陋)。有没有更好的办法?

but this jsut tried to redirect to that path in my app, which doesn't exist. The solution I know of is to do manual redirection in a $scope.$on('$routeChangeStart') in a top-level controller, but this is a lot of code duplication (and it's ugly). Is there a better way?

推荐答案

要我知识,这是不可能的,因为 routeProvider 处理内部路由只。

To my knowledge, this is not possible, as the routeProvider handles internal routes only.

你能虽然做的是

$routeProvider
.when(...)
.otherwise({
    controller: "404Controller",
    template: "<div></div>"
});

,然后只用 window.location.href ='http://yourExternalSite.com/404.html'在控制器中。

这篇关于角路线 - 重定向到一个外部网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆