angular-component / router

Angular Component Router - A declarative router for Angular applications
MIT License
253 stars 16 forks source link

feat: Support loader function as input for route component #97

Open brandonroberts opened 2 years ago

brandonroberts commented 2 years ago

Loaders can be used to fetch data for the component, run checks such as auth, redirect, and more.

import { Component } from '@angular/core';

@Component({
  template: `
    <router>
      <route path="/lazy"
        [load]="components.lazy"
        [loader]="() => Promise<Response> | Observable<Response>">
      </route>
    </router>
  `,
})
export class MyComponent {
  data$: Observable<Data> = getLoaderData();

  constructor(private loaderData$: LoaderData) {}

  components = {
    lazy: () => import('./lazy/lazy.component')
  };
}
mainawycliffe commented 2 years ago

@brandonroberts I am looking to familiarize myself with the inner working of this project, would you mind if I took a crack at this.

brandonroberts commented 2 years ago

Cool @mainawycliffe. You're welcome to, but I wouldn't put too much effort into it at the moment. I'm still evaluating this vs alternative options for routing

mainawycliffe commented 2 years ago

@brandonroberts Thanks. That looks interesting, will take a look while I get a chance. If it's what I think it is, I am really looking forward to it.