角度路由返回空页面

问题描述 投票:2回答:5

我有个问题。

https://stackblitz.com/edit/angular-sc7zsc

我的组件组合不被称为...为什么?我已经看到其他人发帖但它没有解决我的问题谢谢

angular routing
5个回答
3
投票

修复了此处的代码,不要忘记浏览“合成”页面。 Composition.component

<!doctype <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

</head>
<body>


  <nav class="navbar navbar-expand-sm bg-dark navbar-dark navbar">
    <!-- Brand -->
      <a routerLink="" class="pull-left">
        <img src="//www.behi.fr/wp-content/themes/behi-wp/assets/images/logo-softee.svg" class="logo-softee">
      </a> 

    <!-- Links -->
    <ul class="navbar-nav">

      <li class="nav-item" routerLinkActive="active" >
        <a class="nav-link" routerLink ="Composition" >Composition</a>
      </li>
      <div *ngIf="validCompo;then green_circle else red_circle">
          <ng-template #red_circle><img name="redCircle" style="width:15px;height:15px;margin-left:-45px;margin-top: 20px;" src="../../assets/images/circle/red_circle_16.png"></ng-template>
          <ng-template #green_circle><img name="greenCircle" style="width:15px;height:15px;margin-left:-45px;margin-top: 20px;" src="../../assets/images/circle/green_circle_16.png"></ng-template>
      </div>

    </ul>

  </nav>
<router-outlet></router-outlet> // <== feed your content from here
</body>
</html>

0
投票

你只需要放置router-outlet标签

将router-outlet标记保留在要显示路由组件的位置

这是stackblitz Forked Stackblitz的分叉回购


0
投票

在index.html文件的head部分添加基本路径

<base href="/">

在app.component.html中添加<router-outlet></router-outlet>,您也更改了index.html代码。请不要更改index.html,而是添加上面建议的基本路径。


0
投票

你错过了<router-outlet> </router-outlet>请在app.component html文件中导航后添加以下代码。

<router-outlet> </router-outlet>

-1
投票

问题已解决。如图所示更新

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.