question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with angular Router

See original GitHub issue

I’m receiving an error I haven’t been able to find my way around. I’m on Storybook 5.0.10 using angular.

Here is the error:

Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'. (" <a *ngIf="tabType === 'link'" [ERROR ->][routerLink]="" [fragment]="tab.id" (click)="!!select(tab.id)" class="util-tabset__li"): ng:///DynamicModule/UtilTabsetComponent.html@20:8 Can't bind to 'fragment' since it isn't a known property of 'a'. (" <a *ngIf="tabType === 'link'" [routerLink]="" [ERROR ->][fragment]="tab.id" (click)="!!select(tab.id)" class="util-tabset__link" "): ng:///DynamicModule/UtilTabsetComponent.html@20:24
Error: Template parse errors:
Can't bind to 'routerLink' since it isn't a known property of 'a'. ("

      <a *ngIf="tabType === 'link'"
        [ERROR ->][routerLink]="" [fragment]="tab.id"
        (click)="!!select(tab.id)"
        class="util-tabset__li"): ng:///DynamicModule/UtilTabsetComponent.html@20:8
Can't bind to 'fragment' since it isn't a known property of 'a'. ("

      <a *ngIf="tabType === 'link'"
        [routerLink]="" [ERROR ->][fragment]="tab.id"
        (click)="!!select(tab.id)"
        class="util-tabset__link"
"): ng:///DynamicModule/UtilTabsetComponent.html@20:24
    at syntaxError (http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:11068:17)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:29243:19)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:34809:37)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:34796:23)
    at http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:34739:62
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:34739:19)
    at http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:34649:19
    at Object.then (http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:11059:77)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (http://localhost:6006/vendors~main.0afdbd165a15faa9fe9e.bundle.js:34648:26)

and here is my story:

import { storiesOf, moduleMetadata } from '@storybook/angular';

import { UtilTabDirective } from './util-tab.directive';
import { UtilTabsetComponent } from './util-tabset.component';

// Initiate story
storiesOf('Utility/Tabs/Tab Set', module)
    .addDecorator(
        moduleMetadata({
            declarations: [UtilTabsetComponent, UtilTabDirective],
        }),
    )
    .add('Tab Set', () => ({
        component: UtilTabsetComponent,
        props: {
        },
    }))

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

24reactions
lppeddcommented, Aug 14, 2019

There is no need to mock the RouterLinkWithHref Directive.
Just remember to provide a value for the APP_BASE_HREF token. Example:

moduleMetadata({
  declarations: [EntityTypeComponent],
  imports: [NgZorroAntdModule, HttpClientModule, RouterModule.forRoot([])],
  providers: [{ provide: APP_BASE_HREF, useValue: '/' }]
})

Use forRoot even if in the original Module you’ve used forChild.


Or, just discovered, use RouterTestingModule. Example:

moduleMetadata({
  declarations: [EntityTypeComponent],
  imports: [NgZorroAntdModule, HttpClientModule, RouterTestingModule],
  providers: [{ provide: APP_BASE_HREF, useValue: '/' }]
})
7reactions
blemairecommented, Apr 24, 2019

More an Angular issue that a SB issue but here it is:

You need to add RouterModule to the list of declarations:

moduleMetadata({
   declarations: [UtilTabsetComponent, UtilTabDirective, RouterModule],
}),
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Angular routing - Medium
Here is the summary of possible troubles: 'router-outlet' is not a known element — did you export RouterModule in your app-routing. module.
Read more >
Issues · angular/router - GitHub
Issues list ; Routing works wrong with included routes. #449 opened on Jan 27, 2021 ; Angular routing uses window.location url for routing...
Read more >
Angular 4 Routing Issues - Stack Overflow
Try Changing the route to some thing like this const appRoutes: Routes = [ { path:'', redirectTo: 'first', pathMatch: 'full' }, { path: ......
Read more >
Some Tips For Angular Routing Issues - C# Corner
* Define what the router should do if it receives a navigation request to the current URL. * current URL. Default is 'ignore'....
Read more >
Common Routing Tasks - Angular
This topic describes how to implement many of the common tasks associated with adding the Angular router to your application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found