简体   繁体   English

角度2 http://和https://路线

[英]angular 2 http:// and https:// routes

There is an Angular 2 based application with two routes: 有一个基于Angular 2的应用程序,它有两条路线:

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 ". “ / home”路由应转到“ http:// mysite / home ”,“ / login”应转到“ https:// mysite / login ”。 Please pay attention the first one starts with "http://" and the second one starts with "https://". 请注意,第一个以“ http://”开头,第二个以“ https://”开头。 How is it possible to configure the router to use different origins for routes? 如何将路由器配置为对路由使用不同的来源? Or at least http / https for the same origin? 或至少有相同来源的http / https?

This is not something particular to Angular2. 这对Angular2而言并不是特别的。 The routing takes whatever the schema is from the URL when you load the application. 加载应用程序时,路由将从URL获取任何架构。 You have a couple of options to get the login to require HTTPs. 您有两种选择来使登录名需要HTTP。

  • Always load the app over HTTPs. 始终通过HTTP加载应用程序。 Not a bad practice in general, and many web applications do that nowdays. 通常,这不是一个坏习惯,如今许多Web应用程序都这样做。
  • 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. 为您的Web服务器使用一个重写插件(对于Apache来说是mod-rewrite,对于IIS是IIS重写),可以将/ login路由的所有HTTP请求重定向到HTTP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM