admin管理员组

文章数量:1327843

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!

本文标签: javascripthow do I redirect to external URL using angularjs routeProviderStack Overflow