如何使用angularjs routeProvider重定向到外部URL

时间:2022-10-30 10:33:05

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

我想让我的网站访问者根据routeParams转到特定的子域名

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

例如,如果他们转到“http://example.com/foo”,他们将被重定向到“http://foo.example.com”

Can I do that using the routeProvider with something like:

我可以使用routeProvider执行以下操作:

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

1 个解决方案

#1


4  

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执行此操作。如果要将用户重定向到其他子域,请使用带有所需URL的window.location。但是,请考虑这将带您进入您的应用程序。然而,这可能是你所期待的:D

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

Hope that helps you out!

希望能帮到你!

#1


4  

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执行此操作。如果要将用户重定向到其他子域,请使用带有所需URL的window.location。但是,请考虑这将带您进入您的应用程序。然而,这可能是你所期待的:D

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

Hope that helps you out!

希望能帮到你!