V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
77yf77yf77yf
V2EX  ›  前端开发

angular resolver 给 ActivatedRoute 传了内部数据为空(但本身不为空)的对象

  •  
  •   77yf77yf77yf · 10 天前 · 245 次点击

    Resolver: export const homeDataFetchGuard = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Response<Array<DisplayAnime>>> => { return inject(AnimeService).getUpdAniAnimeList(); };

    http 服务: getUpdAniAnimeList() { return this.httpClient.get<Response<Array<DisplayAnime>>> (${environment.apiUrl}/anime/updAnimeList); }

    路由模块: const routes: Routes = [{ path: '', component: MainComponent, children:[ { path: '', component: HomeComponent, resolve: { data: homeDataFetchGuard }}, ] }, { path: '**', redirectTo: '' } ];

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

    component:

    constructor(rivate route: ActivatedRoute) { }

    ngOnInit(): void { this.route.data.pipe(map(data => data as Response<Anime>)).subscribe(res => { console.log(res.code); //里面的数据为 undefined });

    }

    大哥们帮忙看看为什么触发这个订阅时 res 内部的数据都为 undefined ,如果代码不够详细我可以提供更多,问题棘手的话我可以付费

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   771 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 20:48 · PVG 04:48 · LAX 13:48 · JFK 16:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.