Skip to content

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

Open
@brandonroberts

Description

@brandonroberts

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')
  };
}

Activity

mainawycliffe

mainawycliffe commented on Jul 11, 2022

@mainawycliffe

@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

brandonroberts commented on Jul 11, 2022

@brandonroberts
CollaboratorAuthor

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

mainawycliffe commented on Jul 11, 2022

@mainawycliffe

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @brandonroberts@mainawycliffe

      Issue actions

        feat: Support loader function as input for route component · Issue #97 · angular-component/router