延迟加载角上的解析器 [英] resolver on lazy loading angular

查看:61
本文介绍了延迟加载角上的解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在加载延迟加载模块之前添加解析器?我尝试将 resolve 添加到routs配置中,但未触发,也没有在网络上找到任何有用的东西.任何帮助将不胜感激

is there a way to add a resolver before loading a lazy load module? i tried to add resolve to the routs configuration but it is not triggered, also didn't find any thing useful about it on the web. any help would be appreciated

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
// services
import {SecondResolverService} from "./second.resolver.service";

const routes: Routes = [
  { path: 'first' , loadChildren: './first/first.module#FirstModule' },
  { path: 'second', loadChildren: './second/second.module#SecondModule' ,resolve : {data : SecondResolverService}}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

推荐答案

角度延迟加载的文档

此配置始终对我有用.如果这不起作用,则您的解析器可能有问题.

This config always works for me. If this doesnt work there may be something wrong with your resolver.

const routes: Routes = [
  {
    path: 'second',
    loadChildren: () => import('/second/second.module')
      .then(m => m.SecondModule),
    resolve: {
      data: SecondResolverService
    }
  },

这篇关于延迟加载角上的解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆