GVKun编程网logo

主页使用路由器出口在 Angular 11 中呈现两次(路由器的主页)

13

在这篇文章中,我们将带领您了解主页使用路由器出口在Angular11中呈现两次的全貌,包括路由器的主页的相关情况。同时,我们还将为您介绍有关Angular-如何添加/删除路由器出口、Angular2–

在这篇文章中,我们将带领您了解主页使用路由器出口在 Angular 11 中呈现两次的全貌,包括路由器的主页的相关情况。同时,我们还将为您介绍有关Angular - 如何添加/删除路由器出口、Angular 2 – 没有可怕URL的命名路由器出口、Angular 2路由器 – 命名出口、Angular 2:使用路由器测试组件的知识,以帮助您更好地理解这个主题。

本文目录一览:

主页使用路由器出口在 Angular 11 中呈现两次(路由器的主页)

主页使用路由器出口在 Angular 11 中呈现两次(路由器的主页)

如何解决主页使用路由器出口在 Angular 11 中呈现两次?

我想显示没有标题的登录页面,但主页组件渲染了两次,我在主页上使用了主页组件,而不是应用程序组件,但仍在重复。稍微调查一下我知道 <router-outlet></router-outlet> 标签使家出现两次,但我不知道如何解决这个问题。我使用 *ngIf 是为了在登录页面处于活动状态时隐藏标题。

app.component.html

<app-header *ngIf="hiHead"></app-header>

<router-outlet></router-outlet> 
<app-footer></<app-footer>

app.component.ts

import { Router,NavigationStart } from ''@angular/router'';

@Component({
  selector: ''app-root'',templateUrl: ''./app.component.html'',styleUrls: [''./app.component.css'']
})
export class AppComponent {
  title = ''cdls-app'';
  hiHead: boolean = false;

  ngOnInit() {
  }

  constructor(private router: Router) {
    // on route change to ''/login'',set the variable showHead to false
      router.events.forEach((event) => {
        if (event instanceof NavigationStart) {
          if (event[''url''] == ''/login'') {
            this.hiHead = false;
          } else {
            console.log("NU")
            this.hiHead = true;
          }
        }
      });
    }
}

<app-footer></app-footer>

app-routing.module.ts

import { NgModule } from ''@angular/core'';
import { RouterModule,Routes } from ''@angular/router'';
import { HomeComponent } from ''./home/home.component'';
import { LoginComponent } from ''./login/login.component'';
import { RegisterformComponent } from ''./registerform/registerform.component'';

const routes: Routes = [
  { path: ''registro'',component: RegisterformComponent },{ path: ''login'',component: LoginComponent },{ path: ''home'',component: HomeComponent },{ path:'''',redirectTo:''home'',pathMatch:''full'' },{ path: ''**'',pathMatch:''full'' }
];

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

home.component.html

         <divtabindex="-1" uk-slideshow="autoplay: true autoplay-interval: 6000 animation: push pause-on-hover: false">

            <ul>
                <li>
                    <imghttps://www.jb51.cc/tag/nes/" target="_blank">ness(92%)" data-src="https://images.pexels.com/photos/4039155/pexels-photo-4039155.jpeg?cs=srgb&dl=pexels-cottonbro-4039155.jpg&fm=jpg" alt="" uk-cover uk-img>
                    <divuk-scrollspy="cls: uk-animation-slide-right; repeat: true">
                        <h3>Familias</h3>
                    </div>
                        
                    <divuk-scrollspy="cls: uk-animation-slide-left; repeat: true">
                        <phttps://www.jb51.cc/tag/ott/" target="_blank">ottom:0; padding-bottom:0; padding-top:22%; padding-left:50%; padding-right:30px; font-family:''Lato'',sans-serif; font-size:3.2vw; color:#fdfefe">Somos una comunidad que se apoya unos a otros. Conéctate con otras familias</p>
                        <h3><ahttps://www.jb51.cc/tag/decoration/" target="_blank">decoration: none; margin-top:4px; padding-left:0; color: #fbf005; font-size:2.5vw; background-color:transparent;"href="#"><i></i>  Aprende Más</a></h3>


                    </div>
                    
                </li>    
               
                <li>
                    <imghttps://www.jb51.cc/tag/nes/" target="_blank">ness(92%)" data-src="https://images.pexels.com/photos/5638612/pexels-photo-5638612.jpeg?cs=srgb&dl=pexels-askar-abayev-5638612.jpg&fm=jpg" alt="" uk-cover uk-img>
                    <divuk-scrollspy="cls: uk-animation-slide-bottom; repeat: true">
                        <h3>Profesionales</h3>
                    </div>
                    <divuk-scrollspy="cls: uk-animation-slide-top; repeat: true">
                        <phttps://www.jb51.cc/tag/ott/" target="_blank">ottom:0; padding-bottom:0; padding-top:22%; padding-left:50%; padding-right:30px; font-family:''Lato'',sans-serif; font-size:3.2vw; color:#fdfefe">Somos el punto de contacto con otros profesionales de la salud,únete a nosotros</p>
                         <h3><ahttps://www.jb51.cc/tag/decoration/" target="_blank">decoration: none; margin-top:4px; padding-left:0; color: #0548fb; font-size:2.5vw; background-color:transparent;"href="#"><i></i>  Conéctate</a></h3>
                    </div>
                </li>
                <li>
                    <imghttps://www.jb51.cc/tag/nes/" target="_blank">ness(92%)" data-src="https://images.pexels.com/photos/4386466/pexels-photo-4386466.jpeg?cs=srgb&dl=pexels-karolina-grabowska-4386466.jpg&fm=jpg" alt="" uk-cover uk-img>
                    <divuk-scrollspy="cls: uk-animation-slide-top; repeat: true">
                        <h3>Investigación</h3>
                    </div>
                    <divuk-scrollspy="cls: uk-animation-fade; repeat: true">
                        <phttps://www.jb51.cc/tag/ott/" target="_blank">ottom:0; padding-bottom:0;font-family:''Lato'',sans-serif; font-size:3.2vw; color:#fdfefe">Investigamos para conocer más sobre CdLS con el apoyo de profesionales</p>
                        <h3><ahttps://www.jb51.cc/tag/decoration/" target="_blank">decoration: none; margin-top:4px; padding-left:0; color: #fb053d; font-size:2.5vw; background-color:transparent;"href="#"><i></i>  Conéctate</a></h3>
                    </div>
                </li>
            </ul>

            <ahref="#" uk-slidenav-prevIoUs uk-slideshow-item="prevIoUs"></a>
            <ahref="#" uk-slidenav-next uk-slideshow-item="next"></a>

        </div>

<div uk-grid uk-scrollspy="cls: uk-animation-fade; target: .uk-card-body; delay: 500; repeat: true">
    <div>
    <h2>¿Tienes Algún Familiar Diagnósticado con CdLS?</h2>
    <p>El síndrome de Cornelia de Lange ocurre en aproximadamente 1 de cada 10,000 nacimientos,actualmente en Colombia se han identificado alrededor de 100 casos,en los que la Fundación ha ayudado a familias con pacientes con esta rara enfermedad.</p>
    </div>
</div>

<divuk-grid uk-scrollspy="cls: uk-animation-slide-bottom; target: .uk-card; delay: 300; repeat: true">
<div>
    <div>
        <divuk-grid>
            <div>
                <imgwidth="" height="" src="https://images.pexels.com/photos/8944291/pexels-photo-8944291.jpeg?cs=srgb&dl=pexels-anastasia-shuraeva-8944291.jpg&fm=jpg">
            </div>
            <div>
                <h3https://www.jb51.cc/tag/ott/" target="_blank">ottom uk-text-center">Familias</h3>
                
            </div>
        </div>
    </div>
    <div>
        <p>Nuestra fuerza proviene de nuestra comunidad de familias que se apoyan unos a otros. podemos conectarte con otras familias CdLS que atraviesan por retos similares</p>
    </div>
    <div>
        <a href="#"><i></i> Conoce Más</a>
    </div>
    </div>

    <div>
    <div>
        <divuk-grid>
            <div>
                <imgwidth="" height="" src="https://images.pexels.com/photos/5327653/pexels-photo-5327653.jpeg?cs=srgb&dl=pexels-thirdman-5327653.jpg&fm=jpg">
            </div>
            <div>
                <h3https://www.jb51.cc/tag/ott/" target="_blank">ottom uk-text-center">Profesionales</h3>
                
            </div>
        </div>
    </div>
    <div>
        <p>Si eres profesional en ciencias de la salud,únete a nosotros y conéctate con otros profesionales en el campo de estudio del sindrome del CdLS</p>
    </div>
    <div>
        <a href="#"><i></i> Conoce Más</a>
    </div>   
</div>

<div>
    <div>
        <divuk-grid>
            <div>
                <imgwidth="" height="" src="https://images.pexels.com/photos/4033304/pexels-photo-4033304.jpeg?cs=srgb&dl=pexels-edward-jenner-4033304.jpg&fm=jpg">
            </div>
            <div>
                <h3https://www.jb51.cc/tag/ott/" target="_blank">ottom uk-text-center">Investigación</h3>
                
            </div>
        </div>
    </div>
    <div>
        <p>Realizamos investigaciones para conocer más sobre el CdLS con el apoyo de profesionales en ciencias de la salud</p>
    </div>
    <div>
        <a href="#"><i></i> Conoce Más</a>
    </div>

    
</div>
</div>

<div uk-grid uk-scrollspy="cls: uk-animation-fade; target: .uk-card-body; delay: 500; repeat: true">
    <div>
    <h2>¿Quieres Ayudar? Únete y Sé Parte del Cambio,Ayúdando a Otros</h2>
    
    </div>
</div>

<divuk-scrollspy="cls: uk-animation-slide-left; repeat: true" uk-grid>
    <div>
        <img src="https://images.pexels.com/photos/3204051/pexels-photo-3204051.jpeg?cs=srgb&dl=pexels-harrison-haines-3204051.jpg&fm=jpg" alt="" uk-cover>
        <canvas width="600" height="400"></canvas>
    </div>
    <div>
        <div>
            <h3>Donaciones</h3>
            <p>Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt.</p>
        </div>
    </div>
</div>

<div uk-grid uk-scrollspy="cls: uk-animation-fade; target: .uk-card-body; delay: 500; repeat: true">
    <div>
    <h2></h2>
    
    </div>
</div>

<divuk-scrollspy="cls: uk-animation-slide-right; repeat: true" uk-grid>
    <div>
        <img src="https://images.pexels.com/photos/3184397/pexels-photo-3184397.jpeg?cs=srgb&dl=pexels-fauxels-3184397.jpg&fm=jpg" alt="" uk-cover>
        <canvas width="600" height="400"></canvas>
    </div>
    <div>
        <div>
            <h3>Voluntariado</h3>
            <p>Lorem ipsum dolor sit amet,sed do eiusmod tempor incididunt.</p>
        </div>
    </div>
</div>

<div uk-grid uk-scrollspy="cls: uk-animation-fade; target: .uk-card-body; delay: 500; repeat: true">
    <div>
    <h2>Casos CdLS en Colombia</h2>

    </div>
</div>

<div>
    <iframe  width="60%" height="auto" src="https://datastudio.google.com/embed/reporting/7c8d7d55-ee22-4185-852a-526a8c6f67da/page/RWqWC" frameborder="0"allowfullscreen></iframe>
</div>


<div uk-grid uk-scrollspy="cls: uk-animation-fade; target: .uk-card-body; delay: 500; repeat: true">
    <div>
    <h2>Somos Miembros Activos</h2>
    
    </div>
</div>




<divhttps://www.jb51.cc/tag/ott/" target="_blank">ottom:15px; margin-left:auto: margin-right:auto; background-color: #f8f9f9">
<divtabindex="-1" uk-slider="autoplay: true; autoplay-interval: 0; veLocity: 0.03; easing: linear; pause-on-hover: false; draggable: false;">

    <ul>
        <li>
            <div>
                <img data-src="assets/images/cdlsFederationlogo.png" alt="cdlsFederation"uk-img>
                <div><h1></h1></div>
            </div>
        </li>
        <li>
            <div>
                <img data-src="assets/images/Aliber.png" alt=""uk-img>
                <div><h1></h1></div>
            </div>
        </li>
        <li>
            <div>
                <img data-src="assets/images/Fenadeclogo.png" alt=""uk-img>
                <div><h1></h1></div>
            </div>
            
        </li>
        <li>
            <div>
                <img data-src="assets/images/EnHulogo.png" alt=""uk-img>
                <div><h1></h1></div>
            </div>

        </li>
       
    </ul>

    <ahref="#" uk-slidenav-prevIoUs uk-slider-item="prevIoUs"></a>
    <ahref="#" uk-slidenav-next uk-slider-item="next"></a>

</div></div>


       
<div uk-grid uk-scrollspy="cls: uk-animation-fade; target: .uk-card-body; delay: 500; repeat: true">
    <div>
        <h2>¿Tienes Preguntas? Nosotros te las respondemos!</h2>
        <p>Si necesitas asistencia,estamos aquí para ti!</p>
    </div>
    <divhttps://www.jb51.cc/tag/ott/" target="_blank">ottom:30px;" uk-scrollspy="cls: uk-animation-fade; target: .uk-button-primary; delay: 500; repeat: true">
        <button>Déjanos tus datos</button>
    </div>
</div>

login.component.html

<body>

<divuk-grid>
    <div>
        <divhttps://www.jb51.cc/tag/nor/" target="_blank">norepeat">
            <div>
    <div>
        <divuk-grid>
            <div>
                <imgwidth="80" height="80" data-src="/assets/images/logofundacion.png" uk-img>
            </div>
            <div>
                <h3https://www.jb51.cc/tag/ott/" target="_blank">ottom uk-text-center">Inicio de Sesión</h3>
                </div>
        </div>
    </div>
    <div>
        <form>
             <fieldset>

        <span>Usuario</span>
        <div>
        <div>
        <spanuk-icon="icon: user"></span>
            <inputtype="text" placeholder="usuario">
        </div>
        </div>

        <span>Contraseña</span>
        <div>
         <div>
            <spanuk-icon="icon: lock"></span>
            <inputtype="text" placeholder="">
        </div>
        </div>
        <span>¿Todavía no tienes una cuenta? <ahref="/registro"> Regístrate gratis</a></span>

    



    </fieldset>
</form>
    </div>
    <div>
        <button href="#">Iniciar Sesión</button>
    </div>
</div>
        </div>
    </div>
</div>

</body>

解决方法

虽然它可能无助于渲染您的页面两次。我不认为使用 router.events.foreach() 是确定您是否在登录页面上的好方法。

为此,您可以在路线上使用 data 属性。

在路线中:

const ROUTES = [
  {
    path: ''/login'',component: LoginComponent,data: { hiHead: false }
  }
]

获取数据:

constructor(
  private route: ActivatedRoute,...
) { }

ngOnInit(): void {
    this.hiHead = this.route.snapshot.data[''hiHead'']
    ...
}

Angular - 如何添加/删除路由器出口

Angular - 如何添加/删除路由器出口

如何解决Angular - 如何添加/删除路由器出口?

问题:

  1. 如何添加/删除路由器插座?

示例 1:

基本网址: /meal-planner/(userprofile:user-profile//mealprofile:meal-profile//shoppinglist:shopping-list)

操作:删除路由器插座的mealprofile

修改后的网址: (userprofile:user-profile//shoppinglist:shopping-list) -


示例 2:

基本网址: /meal-planner/(userprofile:user-profile)

操作:添加 2 个路由器网点 - 膳食资料和购物清单

修改后的网址: (userprofile:user-profile//mealprofile:meal-profile//shoppinglist:shopping-list)


我的尝试:

this.route.snapshot.children.forEach(child => console.log(child)); //DOES NOT PRINT ANYTHING
console.log(this.route.snapshot.outlet); // PRINTS mealoptimizer
console.log(JSON.stringify(this.route.snapshot.params)); //DOES NOT PRINT ANYTHING

我什至无法提取网址的这一部分:(userprofile:user-profile//mealprofile:meal-profile//shoppinglist:shopping-list)


  1. 如何添加/更新查询参数?

示例 1:

基本网址: /meal-planner/(userprofile:user-profile//mealprofile:meal-profile//shoppinglist:shopping-list)?mealplannermode=update

操作:添加查询参数

修改后的网址: /meal-planner/(userprofile:user-profile//mealprofile:meal-profile//shoppinglist:shopping-list)?mealplannermode=update&shoppinglistmode=add


示例 2:

基本网址: /meal-planner/(userprofile:user-profile//mealprofile:meal-profile//shoppinglist:shopping-list)?mealplannermode=update&shoppinglistmode=add

操作:更新查询参数

修改后的网址: /meal-planner/(userprofile:user-profile//mealprofile:meal-profile//shoppinglist:shopping-list)?mealplannermode=create&shoppinglistmode=add

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Angular 2 – 没有可怕URL的命名路由器出口

Angular 2 – 没有可怕URL的命名路由器出口

我想要两个路由器插座,主插座和模态插座.导航到/ login时,我想在主插座中显示我的主组件,在模块插座中显示我的登录组件.像这样的东西:

{
   path: 'login',component: HomeComponent
},{
   path: 'login',component: LoginComponent,outlet: 'modal'
}

这可以通过使用像/ home(modal:login)这样可怕的辅助URL来实现,但当然没有人希望他们的URL看起来像那样.

如果没有这些网址,我该如何解决?

解决方法

为什么不选择无组件路线,

{
    path: 'login',children: [
        {
            path: '',component: HomeComponent
        },{
            path: '',outlet: 'modal'
        }
    ]
}

这将确保当您的路由是/ login时,HomeComponent将进入主插座,LoginComponent将转到router-outlet,名称为“modal”.

Angular 2路由器 – 命名出口

Angular 2路由器 – 命名出口

文档不是很好,但我试图在同一页/路由上有不同的路由器出口.

我的app.component.html中有这个

<router-outlet></router-outlet>
<router-outlet name="dashboard"></router-outlet>

我的app.routes.ts

{
    path: '',component: HomeComponent,outlet: 'primary'
},{
    path: '',component: DashboardComponent,outlet: 'dashboard'
},{
    path: '**',redirectTo: '404'
}

所以在我的首页上(即“example.com”,而非“example.com;仪表板:仪表板”)我想在主路由器插座中显示Home组件,在显示板插座中显示我的Dashboard组件.这适用于ngrs / router,但由于它已被弃用,我正在尝试迁移.没有仪表板:角度/路由器中的仪表板是否可能?

有了这个配置,我正被重定向到404.我也试过这个没有运气:

{
    path: '',children: [
        {
            path: '',outlet: 'dashboard'
        }
    ]
},

有没有人设法让命名的路由器插座工作?

UPDATE
关于从ngrx / router到angular / router的迁移说明,你应该能够:

{
    path: 'blog',outlet: 'main'
},{
    path: 'blog',component: RegisterComponent,outlet: 'dashboard'
}

但是当我访问example.com/blog时,我在控制台中收到此错误:

Error: Cannot match any routes: ‘blog’

https://github.com/ngrx/router/blob/master/docs/overview/migration.md

试试这个配置:
{
    path: 'wrap',children: [
        {
            path: 'dash',outlet: 'dashboard'
        }
    ]
}

有:

this.router.navigateByUrl('/wrap(dashboard:dash)');

我不知道为什么需要一个url片段(比如我添加的“wrap”)但是它有效……

和其他人:

{
    path: 'blog',outlet: 'dashboard'
}

有:

this.router.navigateByUrl('/(main:blog)');
this.router.navigateByUrl('/(dashboard:blog)');

Angular 2:使用路由器测试组件

Angular 2:使用路由器测试组件

我正在编写使用routeLink的最简单的组件:
@Component({
    selector: 'memorySnippet',templateUrl: '<div*ngIf="memory" 
                  [routerLink]="['MainPanel','MemoryPanel',{'id' : this.memory.id}]">',directives: [CORE_DIRECTIVES,ROUTER_DIRECTIVES]
})
export class MemorySnippetComponent {
    @input() memory: Memory;
}

我尝试测试此组件时会出现此问题.我添加路由器链接Karma的那一刻抱怨缺少提供者:

添加所有提供商后,Karma要求我得到这个:

beforeEachProviders(() => [
    MemorySnippetComponent,MEMORY_SERVICE_PROVIDERS,ROUTER_PROVIDERS,ApplicationRef
]);

但是当我运行测试时,我得到了这个错误:

EXCEPTION: EXCEPTION: Error during instantiation of Token RouterPrimaryComponent! (RouterLink -> Router -> RouteRegistry -> Token RouterPrimaryComponent).

ORIGINAL EXCEPTION: unimplemented

ORIGINAL STACKTRACE:
Error: unimplemented

我究竟做错了什么??? Angular 2(2.0.0-beta.1)还没准备好用路由器指令测试组件吗?

对于带有新路由器的RC4现在使用…
beforeEach(() => addProviders([
  APP_ROUTER_PROVIDERS,// must be first
  {provide: APP_BASE_HREF,useValue: '/'},// must be second
  {provide: ActivatedRoute,useClass: Mock},{provide: Router,useClass: Mock}
]));

使用这种方法的github项目是……

https://github.com/danday74/angular2-coverage

我们今天的关于主页使用路由器出口在 Angular 11 中呈现两次路由器的主页的分享就到这里,谢谢您的阅读,如果想了解更多关于Angular - 如何添加/删除路由器出口、Angular 2 – 没有可怕URL的命名路由器出口、Angular 2路由器 – 命名出口、Angular 2:使用路由器测试组件的相关信息,可以在本站进行搜索。

本文标签: