gpt4 book ai didi

javascript - 为什么我在选择初始加载页面时出现错误?

转载 作者:行者123 更新时间:2023-12-03 01:00:03 25 4
gpt4 key购买 nike

当我在功能模块GalleryModuleModule中选择上传的初始组件时,该组件GalleryComponent

我收到此错误:

Invalid configuration of route '': Array cannot be specified (all components are in the GalleryModuleModule). Tell me what am I doing wrong and how to solve this problem?

应用程序模块:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { GalleryModuleModule } from './gallery-module/gallery-module.module';

@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
GalleryModuleModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}

app.component.html:

<div class="container">
<router-outlet></router-outlet>
</div>

画廊模块.模块:

import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {GalleryComponent} from "./gallery/gallery.component";
import {GalleryAddComponent} from './gallery/gallery-add/gallery-add.component';
import {RouterModule, Routes} from "@angular/router";

const appRoutes: Routes = [
{path: '', redirectTo: '/gallery', pathMatch: 'full'},
{path: 'gallery-add', component: 'GalleryAddComponent'},
];

@NgModule({
imports: [
CommonModule,
RouterModule.forRoot([
appRoutes,
{enableTracing: true}
])
],
declarations: [GalleryComponent, GalleryAddComponent],
exports: [GalleryComponent, GalleryAddComponent RouterModule],
})
export class GalleryModuleModule {
}

最佳答案

您执行了{path: '', redirectTo: '/gallery', pathMatch: 'full'},,但实际上您没有名为 gallery 的路径应该被重定向到。例如,将路由配置更改为:

const appRoutes: Routes = [
{path: '', redirectTo: '/gallery', pathMatch: 'full'},
{path: 'gallery', component: GalleryComponent},
{path: 'gallery-add', component: GalleryAddComponent},

];

并删除 RouterModule.forRoot() 中的额外数组( https://angular.io/api/router/RouterModule#forRoot )(如 @Suresh 提到的)应该可以!

PS:不要忘记导入路由配置中列出的组件(它们不应作为字符串引用)

关于javascript - 为什么我在选择初始加载页面时出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52666041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com