The route specifies that it must have a mode parameter on the end, so the alternative form without a mode parameter at the end of the path, is different.
{ path:'test/display/:mode' ,component:DisplayComponent }
if different to:
{ path:'test/display/' ,component:DisplayComponent }
The query string is not part of the route at all, so adding one is not the equivalent of ":mode".
So, you simply need to specify both of these alternative routes if you want to support route parameters and query strings. Generally it's best practice to use route parameters only for required parameters such as the id of a resource you are requesting/updating. Query string parameters are best used for optional parameters, such as search options, data windowing, or algorithm tweaks.
[{ path:'test/display/:mode' ,component:DisplayComponent },
{ path:'test/display/' ,component:DisplayComponent }]
is what you want. Then you can
test/display/5
and
test/display/?mode=5
To obtain the query string value you need to subscribe to the queryParams of the activatedRoute service.
import { Component, OnInit} from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
export class ExampleComponent implements OnInit {
public mode = null;
constructor(private activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.activatedRoute.queryParams.subscribe((qp: Params) => {
this.mode = qp['mode'];
});
}
}