简体   繁体   English

AWS Amplify with Angular - 停止 URL 重定向到索引

[英]AWS Amplify with Angular - Stop URL redirecting to index

I have an Angular app that I recently migrated to AWS Amplify.我有一个最近迁移到 AWS Amplify 的 Angular 应用程序。 I am having a problem, though, with creating links to particular pages (for example, sending a confirmation link in an email).但是,我在创建指向特定页面的链接时遇到了问题(例如,在电子邮件中发送确认链接)。 Links automatically redirect to the index page.链接自动重定向到索引页面。 The same thing happens if I try to navigate to a page by entering its URL in the address bar, or if I simply reload the page.如果我尝试通过在地址栏中输入其 URL 来导航到某个页面,或者如果我只是重新加载该页面,则会发生同样的事情。

I have an app-routing.module.ts file that used to work before moving to Amplify.我有一个 app-routing.module.ts 文件,该文件在移至 Amplify 之前可以正常工作。 When run from localhost, the links still work fine.从本地主机运行时,链接仍然正常工作。 How do I fix this?我该如何解决?

App-routing.module:应用路由模块:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  {
    path: '',
    loadChildren: './intro/intro.module#IntroModule'
  },
  {
    path: 'login',
    loadChildren: './login/login.module#LoginModule'
  },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

app.module应用模块

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { MaterialModule } from './material/material.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { NgSelectComponent } from './ng-select/ng-select.component';
import { NgxChartsModule } from '@swimlane/ngx-charts';
import { AmplifyAngularModule, AmplifyService } from 'aws-amplify-angular';


@NgModule({
  declarations: [
    AppComponent,
    NgSelectComponent,

  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule,
    FormsModule,
    BrowserAnimationsModule,
    MaterialModule,
    HttpClientModule,
    NgxChartsModule,
    AmplifyAngularModule
  ],
  exports: [
  ],
  providers: [
    AmplifyService,
    { provide: 'APIRoot', useValue: 'https://app.rivver-platform.com/api/' },
    { provide: 'colors1', useValue: ['#3dcc85','#ffbe5c','#7b64e0','#ff8370'] },
    { provide: 'colors1', useValue: ['#3dcc85','#ffbe5c','#7b64e0','#ff8370'] },
    { provide: 'colors2', useValue: ['#51c8e0','#7b64e0','#3dcc85','#ffbe5c'] }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component应用组件

<main [@routeAnimations]="prepareRoute(outlet)">
<router-outlet #outlet="outlet"></router-outlet>
</main>

app.component.ts app.component.ts

import { Component,OnInit } from '@angular/core';
import { RouterOutlet, Router } from '@angular/router';
import { slideInAnimation } from './animations';
import {DomSanitizer} from '@angular/platform-browser';
import {MatIconRegistry} from '@angular/material/icon';
import { LocationStrategy } from '@angular/common';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  animations: [
    slideInAnimation
    // animation triggers go here
  ]
})
export class AppComponent implements OnInit {

  private loaded = false;
  constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer, private locationStrategy: LocationStrategy, private router: Router) {

  ngOnInit() {
    let _this = this;
    setTimeout(function(){
      _this.loaded = true;
    },1);
  }
  prepareRoute(outlet: RouterOutlet) {
    if (!this.loaded){
      history.pushState(null, null, location.href);
    }
    return outlet && outlet.activatedRouteData && outlet.activatedRouteData['animation'];
  }

}

EDIT: I tried removing prepareRoute, AmplifyAngularModule, and AmplifyService but the problem persists.编辑:我尝试删除 prepareRoute、AmplifyAngularModule 和 AmplifyService,但问题仍然存在。

For security purposes, AWS Amplify blocks all links from external sources and redirects them to the index.出于安全目的,AWS Amplify 会阻止来自外部源的所有链接并将它们重定向到索引。 To edit these rules, go to Rewrites and Redirects.要编辑这些规则,请转到重写和重定向。 The following page explains how to use these rules.下一页说明了如何使用这些规则。

https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa

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

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