可以配置Angular2路由器(使用散列位置策略)来保留查询参数吗?当我加载页面时,它会删除查询字符串并将其附加到URL片段,当我单击路由器链接时,查询字符串将完全消失。我希望路由器根本不接触查询字符串,只是保持原样,只修改URL片段。
我指的是用户从其他网站定向到我的网站的状态,我需要保留网址参数以从服务中获取用户ID和数据
APP-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { NavigationExtras } from '@angular/router';
import { HomeComponent } from '../components/home.component';
import { OneComponent } from '../wizard/one.component';
const routes: Routes = [
{ path: '**', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'one', component: OneComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true }) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {
}
app.modul.ts
import './rxjs-extensions';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { AppRoutingModule } from './modules/app-routing.module'
import { HttpModule } from '@angular/http';
import { AppComponent } from './components/app.component';
import { TofesService } from './services/tofes.service';
import { HomeComponent } from './components/home.component';
import { OneComponent } from './wizard/one.component';
import { ExampleOneComponent } from './wizard/example-one.component';
import { ExampleOneStep1Component } from './wizard/example-one-step1.component';
import { ExampleOneStep2Component } from './wizard/example-one-step2.component';
import { ExampleOneStep3Component } from './wizard/example-one-step3.component';
import { ExampleTwoModule } from './wizard/example-two.module';
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpModule,
ExampleTwoModule
],
declarations: [
AppComponent,
HomeComponent,
OneComponent,
ExampleOneComponent,
ExampleOneStep1Component,
ExampleOneStep2Component,
ExampleOneStep3Component,
],
providers: [
TofesService
],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
app.component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css']
})
export class AppComponent {
title = 'Tofes 101 Web';
}