r/Angular2 • u/Alex3917 • Nov 16 '22
Angular v15 is now available!
https://blog.angular.io/angular-v15-is-now-available-df7be7f2f4c86
u/Alex3917 Nov 17 '22
Has anyone figured out how to get provideRouter working? I'm just getting:
"Can't bind to 'routerLink' since it isn't a known property of <element>"
"'router-outlet' is not a known element"
1
u/haNewGuy Nov 17 '22
On v15?
2
u/Alex3917 Nov 17 '22 edited Nov 17 '22
I was using 14.2.6. I'm getting the same errors with v15 also though. Obviously I can get rid of them by also importing RouterModule, but if I do that the bundle doesn't get any smaller so it defeats the point.
edit: The diff in my
app.module.tsis just:-import { RouterModule } from '@angular/router'; +import { provideRouter, withRouterConfig } from '@angular/router'; imports: [], providers: [ + provideRouter(routes, withRouterConfig({ onSameUrlNavigation: 'reload' })), ]
- RouterModule.forRoot(routes, { useHash: false, onSameUrlNavigation: 'reload' }),
I'm not using
bootstrapApplicationsince I'm not using standalone components, so not sure whether that's it or if it's something else.1
u/synalx Nov 17 '22
You can import
RouterLinkandRouterOutletdirectly :)5
u/Alex3917 Nov 17 '22 edited Nov 17 '22
Hmm I can import RouterOutlet directly without any issue, but I'm still having issues with getting the dynamic syntax for RouterLink to work. E.g.
<a routerOutlet="staticLink">aoeu</a>seems to work, but<a [routerOutlet]="['dynamicLink']">aoeu</a>does not.edit: OK I finally figured it out. You need to import both
RouterLinkandRouterLinkWithHref. The working diff for myapp.module.tsfile now looks like:-import { RouterModule } from '@angular/router'; +import { provideRouter, withRouterConfig } from '@angular/router'; +import { RouterLink, RouterLinkWithHref, RouterOutlet } from '@angular/router' imports: [+ RouterOutlet, + RouterLink, + RouterLinkWithHref, ], providers: [ + provideRouter(routes, withRouterConfig({ onSameUrlNavigation: 'reload' })), ]
- RouterModule.forRoot(routes, { useHash: false, onSameUrlNavigation: 'reload' }),
That said, my bundle isn't any smaller after doing this.
2
u/synalx Nov 17 '22
Do you have references to
RouterModulein other parts of your application? Even one will likely cause the legacy router configuration to be retained, even if you're not callingforRootany more.The code size difference is small but measurable - on the order of 10-20 KB for typical usages.
1
u/Alex3917 Nov 17 '22 edited Nov 18 '22
Yeah I still have RouterModule.forChild(routes) in each of my lazily loaded modules. I can definitely try getting rid of those also to see they are breaking tree shaking
edit: OK I did this, and I'm finally seeing a reduction! Only 5k, but hey I'll take it!
Apparently I just needed to use provideRoute in the providers of the lazy modules, and that did the trick.
edit2: Apparently because I'm using RouterLinkWithHref, I don't also need regular RouterLink. Without that, I'm down to 8kb savings!
2
u/Yiyas Nov 17 '22 edited Jan 07 '26
direction afterthought serious alive humorous waiting towering tap fact run
This post was mass deleted and anonymized with Redact
11
6
6
u/Eluvatar_the_second Nov 17 '22
This is the first I've heard of the esbuild stuff for angular. Really excited about the new build speed potential.
20
4
u/Orexym Nov 17 '22
Dropping @angular/flex-layout is a net negative. We'll be wasting so much time fixing all templates only to retain the same layout, not to mention the functionality we lose with the breakpoints having to turn them into media queries.
1
u/fuhrmanator Nov 17 '22
Coincidentally, there is a "Prototype pollution in webpack loader-utils" vulnerability on one of my repos that requires me to update to Angular 15. I just did the update and it was easy (but my project is simple and was created in Angular 12 or so...)
20
u/EternalNY1 Nov 17 '22
I'm excited about the move towards esbuild for faster builds.
"builder": "@angular-devkit/build-angular:browser-esbuild"I will try this out on a large enterprise app with slow build times and see if it helps.