How to fix Angular standalone component: Can't bind to 'routerLink' since it isn't a known property of 'a'
Problem:
When opening your Angular app with a standalone component, you see the following error message:
angular_router_error.txt
Can't bind to 'routerLink' since it isn't a known property of 'a'
Solution
In the component where the error occurs, add
import_router_module.ts
import { RouterModule } from '@angular/router';
and add
router_module_import_example.ts
RouterModule,
to the imports
of the component. Example:
top_bar_component.ts
@Component({
selector: 'app-top-bar',
standalone: true,
imports: [
CommonModule,
RouterModule
],
templateUrl: './top-bar.component.html',
styleUrl: './top-bar.component.sass'
})
export class TopBarComponent {
}
Check out similar posts by category:
Angular, Typescript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow