Компонент, где у вас есть метод like
(назовите этот компонент как Abc)
abc.component.ts
import { Router } from '@angular/router';
constructor(private router: Router) {
}
like(id:string,l:string) {
if (l == 1) {
this.likes=0;
} else {
this.likes=1;
}
this.gs.like(id,this.likes).subscribe((data) => {
console.log(data);
router.navigate(['otherComponentPath']); add this
});
}
abc.module.ts
import { RouterModule } from '@angular/router';
import { AbcComponent } from '<path to the component>';
import { AbcRoutingModule } from '<path to the abc routing module>';
@NgModule({
imports: [
...,
RouterModule,
AbcRoutingModule,
],
declarations: [
AbcComponent,
OtherComponent
]
})
export class AbcModule {
}
abcRouting.module.ts
const routes: Routes = [
...
path: 'otherComponentPath', //this will be in the url
component: OtherComponent
];
@NgModule({
imports: [ RouterModule.forChild(routes) ],
exports: [ RouterModule ]
})
export class AbcRoutingModule {
}