When I navigate to a page with query parameters in my Angular application, the parameters end up disappearing.
For example, if I go here:
http://example.com:8080/TestComponent?OtherName=foo
If reroutes me to here:
http://example.com:8080/TestComponent
Thus, since the query parameters get erased, my subscription to ActivatedRoute returns nothing. This is my routing:
import { Routes } from '@angular/router';
import { TestComponent, PageNotFoundComponent } from './exports/components';
export const ROUTES: Routes = [
{
path: 'TestComponent',
component: TestComponent
},
{
path: '**',
component: PageNotFoundComponent
}
];
Subscription (route is an instance of ActivatedRoute):
this.route.queryParams.subscribe((params: Params) => {
if (params && Object.keys(params).length > 0) {
const OTHER_NAME = params['OtherName'];
}
});
Even if I remove the wildcard path, it still removes the parameters from the URL; therefore, it never goes inside the the above if statement. How can I prevent the query parameter from disappearing?
http://example.com:8080/TestComponent?OtherName=foointo the address bar. Then theRoutesarray takes over and sends me to theTestComponenthtml.routerlinkor withRouter.navigatebut not for the initial URL or when typing the URL in the address bar (as far as I know). There is a feature request to allow a global setting to keep the query parameters.