I am trying to pass a value to index.html , which call app.componenet. I am trying to process the query string tha get passed in my root component before I do a redirect
LINK Goal
http://localhost:4200/index/1
HtML
<app-root></app-root>
APP.Component
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [AppComponentService]
})
export class AppComponent {
constructor(elm: ElementRef,private _service: AppComponentService, private _rout: ActivatedRoute) {
this._rout.params.subscribe(params => {
console.log('id' + params['id']);//value is undefined
});
}
App Routes
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
*****************************UPDATE**********************************************************************
My issue should be coming fro the rout..please keep in mind I am trying to hit the app.comonent first to perform some logic before I do redirect to dashboard
I change my rout to
const routes: Routes = [
{ path: '', component: AppComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })],
exports: [RouterModule]
})
export class AppRoutingModule { }
app.component
constructor(elm: ElementRef,private _service: AppComponentService, private _rout: ActivatedRoute) {
this._rout.params.subscribe(params => {
console.log('id' + params['id']);//value is undefined
//some logic then will redirect to dashboard
});
http://localhost:4200/index/?v=1) you don't need to configure any route and you can obtain it subscribing toqueryParamsinstead ofparams.this._rout.queryParams.subscribe(...)