I'm using the Angular 4/5 currently and let’s say I have 2 components Component 1 and Component 2. Now, I've been given a task that if the URL is http://localhost:4200/?property1=value1, then Component 1 will be displayed and if the URL is http://localhost:4200/?property1=value2, then Component 2 will be displayed.
Since I'm a beginner in Angular, therefore, I'm facing problems in these two tasks.
Finding the values of property1 (i.e. value1 and value 2) from the query string each time.
After finding the value, how to define a logic i.e. which component to show?
Although I find this link, I'm unable to find the logic for using the value to see the component. Please help.
Edit: On working through the @Osman Cea's answer, this is the error I'm getting:
null: ERROR
null: Error: StaticInjectorError[ActivatedRoute]:
__zone_symbol__currentTask: ZoneTask {_zone: Zone, runCount: 0, _zoneDelegates: null, …}
message: "StaticInjectorError[ActivatedRoute]:
StaticInjectorError[ActivatedRoute]:
NullInjectorError: No provider for ActivatedRoute!"
ngDebugContext: DebugContext_ {view: Object, nodeIndex: 1, nodeDef: Object, …}
ngErrorLogger: function () { … }
ngTempTokenPath: null
ngTokenPath: Array(1) []
stack: "Error: StaticInjectorError[ActivatedRoute]:
StaticInjectorError[ActivatedRoute]:
NullInjectorError: No provider for ActivatedRoute!
at _NullInjector.get (webpack-internal:///../../../core/esm5/core.js:1189:19)
at resolveToken (webpack-internal:///../../../core/esm5/core.js:1477:24)
at tryResolveToken (webpack-internal:///../../../core/esm5/core.js:1419:16)
at StaticInjector.get (webpack-internal:///../../../core/esm5/core.js:1290:20)
at resolveToken (webpack-internal:///../../../core/esm5/core.js:1477:24)
at tryResolveToken (webpack-internal:///../../../core/esm5/core.js:1419:16)
at StaticInjector.get (webpack-internal:///../../../core/esm5/core.js:1290:20)
at resolveNgModuleDep (webpack-internal:///../../../core/esm5/core.js:11074:25)
at NgModuleRef_.get (webpack-internal:///../../../core/esm5/core.js:12306:16)
at resolveDep (webpack-internal:///../../../core/esm5/core.js:12804:45)"
__proto__: Object {constructor: , name: "Error", message: "", …}
null: ERROR CONTEXT
null: DebugContext_ {view: Object, nodeIndex: 1, nodeDef: Object, elDef: Object, elView: Object}
component: null
componentRenderElement: app-root
context: null
elDef: Object {nodeIndex: 0, parent: null, renderParent: null, …}
elOrCompView: Object
elView: Object {def: Object, parent: null, viewContainerParent: null, …}
injector: Injector_
nodeDef: Object {nodeIndex: 1, parent: Object, renderParent: Object, …}
nodeIndex: 1
providerTokens: Array(1)
references: Object
renderNode: app-root
view: Object {def: Object, parent: null, viewContainerParent: null, …}
__proto__: Object {elOrCompView: <accessor>, injector: <accessor>, component: <accessor>, …}
null: Error: StaticInjectorError[ActivatedRoute]: