最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how do I redirect to external URL using angularjs routeProvider - Stack Overflow

programmeradmin8浏览0评论

I would like to have my site visitors go to a specific subdomain based on routeParams

for example if they go to "" they will be redirected to ""

Can I do that using the routeProvider with something like:

    $routeProvider
        .when('/:my_affiliate', {
            redirectTo: function(routeParams){
                return 'http://' + routeParams.my_affiliate + '.example';
            },
      })
        ;

I would like to have my site visitors go to a specific subdomain based on routeParams

for example if they go to "http://example./foo" they will be redirected to "http://foo.example."

Can I do that using the routeProvider with something like:

    $routeProvider
        .when('/:my_affiliate', {
            redirectTo: function(routeParams){
                return 'http://' + routeParams.my_affiliate + '.example.';
            },
      })
        ;
Share Improve this question asked Aug 27, 2015 at 21:14 Jared WhippleJared Whipple 1,1714 gold badges17 silver badges40 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You can do this with routeProvider how you state. If you want to redirect a user to a different subdomain use window.location with the desired URL. However, consider this will take you of your application. This may however be what you were expecting :D

$routeProvider
    .when('/:my_affiliate', {
        redirectTo: function(routeParams) {
            window.location = 'http://' + routeParams.my_affiliate + '.example.';
        }
    });

Hope that helps you out!

发布评论

评论列表(0)

  1. 暂无评论