Home:ALL Converter>Angular 2 routing removes URL path

Angular 2 routing removes URL path

Ask Time:2017-05-17T01:28:24         Author:user3334871

Json Formatter

I added routing to my angular 2 app to read query parameters from the URL. The URL looks something like www.myapp.com/projectName/myPage.html?query1=firstName. In my routing code, I have:

import { ModuleWithProviders }  from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { routingComponent } from './app.adminPage';

// Route Configuration
export const routes: Routes = [
  { path: 'myPage.html', component: routingComponent}
];


export const routing: ModuleWithProviders = RouterModule.forRoot(routes);

My example is very simple, as all I am using routing for is reading query parameters from the page. However, when I hit www.myapp.com/projectName/myPage.html?query1=firstName and it routes and serves my component, the URL changes to www.myapp.com/projectName/, which means that if the user refreshes, it loads back to my landing page. I have another page that uses routing to ready query params that doesn't do this, so I am curious as to why this page does that. Is there a way to stop this?

Author:user3334871,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/44007957/angular-2-routing-removes-url-path
yy