Sergey
Sergey

Reputation: 1

angular 2 http:// and https:// routes

There is an Angular 2 based application with two routes:

const appRoutes: Routes = [
    {
        path: 'home',
        component: HomeComponent
    },
    {
        path: 'login',
        component: LoginComponent
    }
];

The "/home" route should go to "http://mysite/home" and "/login" should go to "https://mysite/login". Please pay attention the first one starts with "http://" and the second one starts with "https://". How is it possible to configure the router to use different origins for routes? Or at least http / https for the same origin?

Upvotes: 0

Views: 1172

Answers (1)

Ben Richards
Ben Richards

Reputation: 3575

This is not something particular to Angular2. The routing takes whatever the schema is from the URL when you load the application. You have a couple of options to get the login to require HTTPs.

  • Always load the app over HTTPs. Not a bad practice in general, and many web applications do that nowdays.
  • Use a re-write plugin for your web server (mod-rewrite for Apache, or IIS rewrite for IIS) to redirect all HTTP requests for the /login route to HTTPs.

Upvotes: 1

Related Questions