Routing and Lazy Loading with Standalone Components

Поделиться
HTML-код
  • Опубликовано: 5 авг 2024
  • Now that we can build an application using standalone components, we don't need Angular modules (also called NgModules).
    But then ... where do we put our routes?
    Let's look at how to do routing, including lazy loading, without an NgModule.
    To create an application without NgModules, we add the list of routes to the bootstrapApplication configuration. In the providers array, we specify provideRouter and pass in our routes.
    To lazy load a set of child routes, use loadChildren.
    To lazy load an individual component, use loadComponent.
    Links
    Simplify with Angular Standalone Components: • Simplify with Angular ...
    Migrating to Standalone Components with Angular CLI: • Migrate to Standalone ...
    Sample code: github.com/DeborahK/Angular-G...
    Content
    00:00 Routing + Lazy Loading with Standalone Components
    00:20 Routing with NgModules (App module)
    00:58 Routing to child routes with NgModules (feature modules)
    01:16 Running to see the routes
    01:53 Migrating components to standalone
    02:09 Routing without NgModules
    03:03 Child Routes without NgModules: provideRouter
    04:04 Child Routes without NgModules: product.route.ts
    05:27 Lazy loading child routes without NgModules: loadChildren
    07:51 Lazy loading standalone components without NgModules: loadComponent
    10:03 Removing Feature NgModules
    10:34 Wrap Up
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    😊About Me
    Hey! I'm Deborah Kurata
    I'm a software developer and RUclips content creator. I speak at conferences such as VS Live and ng-conf. I write articles for freeCodeCamp. And I'm a Pluralsight author with courses in the top 10 most popular (out of 10,000+) over the past 5 years. For my work in support of software developers, I've been recognized with the Microsoft Most Valuable Professional (MVP) award, and I'm a Google Developer Expert (GDE).
    Contact me on Twitter: / deborahkurata
    Find my Pluralsight courses: www.pluralsight.com/profile/a...
    Access my freeCodeCamp articles: www.freecodecamp.org/news/aut...
    View my RUclips content: / @deborah_kurata
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    #angular #bestpractices #angulartutorial #angularstandalonecomponents #standalonecomponents #demo #lazyloading #lazyloadinginangular #angularlazyloading #routinginangular #routingangular #angularrouting
  • НаукаНаука

Комментарии • 63

  • @07bakabaka
    @07bakabaka 9 часов назад

    Kurata Fan here!!! 🙂🙂🙂

  • @user-bm1rv8pf2k
    @user-bm1rv8pf2k 11 месяцев назад +11

    This is probably the cleanest explanation about Standalone Components I've ever seen. You've saved my time lots of time, thank you! 😇

    • @deborah_kurata
      @deborah_kurata  10 месяцев назад +1

      So glad to hear it was useful. Thank you!

    • @Alupl
      @Alupl 6 месяцев назад

      Me too - thanks :) Now it's soo easy :)))

  • @jaimemartin1932
    @jaimemartin1932 Месяц назад +1

    I learned Angular thanks to you in Pluralsight, and now I love Angular, just because the good explanations you provide and how easy to understand is.

    • @deborah_kurata
      @deborah_kurata  Месяц назад

      That is wonderful to hear! Glad it's been useful. 😊

  • @Eaglessoft
    @Eaglessoft 7 месяцев назад +2

    i watch your videos on pluralsight seeing you provide free videos on youtube warms my heart.

  • @simenesky
    @simenesky 6 месяцев назад +1

    One of the best tutorilals I found on youtube !!!

    • @deborah_kurata
      @deborah_kurata  6 месяцев назад

      Thank you so much! It's great to hear it was useful!

  • @alfyxxxxx
    @alfyxxxxx 5 месяцев назад +1

    Been looking for a while to implement more than one, or multiple, router-outlet in Angular 17 with all the standalone new stuff. This video was all I needed, appreciate the effort and explanation. Straightforward. You just gained a subscriber.

  • @danielabonvini
    @danielabonvini 5 месяцев назад +1

    I'm using for the first time a standalone component in my application and didn't know how to handle its routing; thankfully your video came up in the search results!
    As always your videos are amazing and full of real world examples. Already saved the other standalone related videos in my watch later list 😃

  • @michaelgolden4370
    @michaelgolden4370 11 месяцев назад

    Deborah, you're a gem! Thanks for always delivering quality videos ❤

    • @deborah_kurata
      @deborah_kurata  10 месяцев назад

      Wow, thank you! Glad they are useful!

  • @barcioch_
    @barcioch_ 10 месяцев назад +1

    I've been looking for this for a few days now. I'm glad I found your channel, Deborah. That's what I call quality conent.

  • @sidneyshuman6738
    @sidneyshuman6738 Год назад

    Lol perfect timing! I'm currently migrating our App to standalone right now 😁

  • @ErickCcsVzla
    @ErickCcsVzla Год назад

    Nice video! Please, keep them coming 😊

  • @sakarsr
    @sakarsr Год назад +2

    Very clean explanation of routing and lazy loading with standalone components. Thank you and good health. please make more videos on angular 16 new features.

    • @deborah_kurata
      @deborah_kurata  Год назад

      That is kind of you to say. Thank you!
      Is there a particular feature you'd like to see more information about?

  • @ansumanmishra9608
    @ansumanmishra9608 Год назад

    Nice explanation! Your teaching skills are excellent

    • @deborah_kurata
      @deborah_kurata  Год назад

      So glad to hear it was useful! Thank you! 😊

  • @sukruozdemir70
    @sukruozdemir70 6 месяцев назад

    You are awesome Debora.. Thank you so much...

    • @deborah_kurata
      @deborah_kurata  6 месяцев назад

      That is very kind of you to say. Thank you!

  • @ankitmvp
    @ankitmvp Месяц назад

    Thanks for this video ... I think this is the best explanation of Standalone Components with Lazy loading ... :)

  • @demidovmaxim1008
    @demidovmaxim1008 10 месяцев назад

    Thank you so musch ! Love this channel.

  • @rajumechanicalhub5805
    @rajumechanicalhub5805 6 месяцев назад

    I love you for your teaching

  • @nayosx
    @nayosx 3 месяца назад

    Muchas gracias!!!! thank you for the lesson

  • @keycuevasmelgarejo
    @keycuevasmelgarejo Год назад

    Buen video! Gracias

  • @andersonrueda1580
    @andersonrueda1580 6 месяцев назад

    Thank you so much!

  • @jyothsnareddy9689
    @jyothsnareddy9689 7 месяцев назад

    The best trainer I have ever known! Your way of teaching has inspired me to learn html , css which iIwas afraid of from 13 years! I have started working on a project from scratch . And I'm using Angular 17. Could you please guide on that..

    • @deborah_kurata
      @deborah_kurata  7 месяцев назад

      Wow! Thank you!
      I have courses on HTML, CSS, Bootstrap, JavaScript, and Git/GitHub here on YT. Let me know if you need any of the links.
      My Angular courses are on Pluralsight: www.pluralsight.com/profile/author/deborah-kurata
      I do have quite a few Angular videos here on YT, but I don't have an Angular course here as of now.
      All the best!

  • @digitaldaridesatv1545
    @digitaldaridesatv1545 Год назад

    Thank soo much!

  • @mean2035
    @mean2035 5 месяцев назад

    very thank you

  • @MultiWarrr
    @MultiWarrr Год назад

    Like before watch

  • @baduy101
    @baduy101 10 месяцев назад

    Hey Deborah, Glad that we can now see your contents here in YT. Very informative contents as always. Btw, what are your thought to standalone all the component? Just a bit confuse on when to use standalone component vs adding it in module. Thanks!

    • @deborah_kurata
      @deborah_kurata  10 месяцев назад

      Thank you!
      I've been doing 100% standalone recently. And I just heard that Angular v17 (due out next month) will default to standalone. So I think the move is to standalone, unless you have a complex use case that does require an NgModule.

  • @user-di1yd4zu4e
    @user-di1yd4zu4e 5 месяцев назад

    This is a great explanation for standard child routes, however, what about nested routes? How can you accomplish this with standalone components? Named router outlets result in 'routes not found' errors. There doesn't seem to be a way to accomplish this currently.

  • @gorkemridvan
    @gorkemridvan 6 месяцев назад

    Thank you for your great explanation Deborah.
    Do you recommend proceeding with full standalone components without using any modules for new projects?

    • @deborah_kurata
      @deborah_kurata  6 месяцев назад +1

      Thank you for the kind words.
      Yes, the community is moving toward full standalone components.

  • @madsxcva
    @madsxcva 5 месяцев назад

    nice

  • @tanushreebhattacharji2611
    @tanushreebhattacharji2611 4 месяца назад

    Awesome video. I had a question.Initially I had implemented a module per component, and module based lazy loading in my app. At that time my main.js bundle size was 2mb. Now I converted to all standalone and implemented lazy loading for standalone components. Now my bundle size is 4mb. Any idea what can be the problem or a solution?

  • @dshakya
    @dshakya Месяц назад

    This has been helpful. Trying to find that other video about bootstraping but couldn't find it in the channel. Would you mind linking it in description or info card? Thanks.

    • @deborah_kurata
      @deborah_kurata  Месяц назад +1

      Glad to hear it was helpful!
      I believe both videos I referred to are links in the description already. The one about bootstrapping for standalone components is called "Simplify with Angular Standalone Components". Let me know if you were looking for something else.

    • @dshakya
      @dshakya Месяц назад +1

      @@deborah_kurata Thanks for that. I did watch the informative video. I suppose I was looking for moving the providers into its own file. I created a new project using latest CLI and basically created the new structure with app.config.ts, where I moved the providers. I then referenced this in main.ts bootstrapApplication like the CLI generated. Much appreciated. Thank you!

  • @ahmedrashad494
    @ahmedrashad494 Год назад

    Thank you so much just i have question can i use path with loadComponent in app.router.ts instead of main.ts

    • @deborah_kurata
      @deborah_kurata  Год назад +1

      Thank you for watching!
      And if I understand your question correctly ... yes!

  • @hemangthanki
    @hemangthanki Год назад +2

    I have recently learned that, loadChildren does not need .then() if the PRODUCT_ROUTES are exported default! (I was wondering why not!!!)

    • @deborah_kurata
      @deborah_kurata  Год назад +2

      Yes! I opted not to cover that thinking most Angular developers weren't familiar with "default exports". But maybe I should have?

    • @toxaq
      @toxaq 9 месяцев назад

      @@deborah_kurata it makes for such clean code. Worth a mention at some point,

  • @havefun5519
    @havefun5519 Год назад +1

    Thanks for the tutorial. BTW, I have a question:
    If we lazyload the product routes, I understood that when we go to the products list page, it will load
    My question is, should I lazyload ProductDetailComponent ?
    Then when we go to the product list page, it will load the lazyChildren, then ProductListComponent will load
    Then when we go to one product detail page, it won't load first via lazyChildren by default
    --------------app routes
    export const routes: Routes = [
    ....
    path: 'products',
    loadChildren: () => import('./products/product.routes').then(r => r.PRODUCT_ROUTES)
    },
    .....
    ];
    --------------product routes
    export const PRODUCT_ROUTES: Routes = [
    { path: '', component: ProductListComponent },
    {
    path: ':id',
    canActivate: [ProductDetailGuard],
    loadComponent: () => import('....'),
    }
    ];

    • @deborah_kurata
      @deborah_kurata  Год назад

      Thank you for watching.
      Sorry for the delay in getting back to you. I wanted time to try this out, but haven't yet.
      I would *think* that would make sense if the 80% case is that the user will only access the product list and not access the product detail. If the 80% case is that the user will access the list to then access the detail, it may not improve the overall experience.