【问题标题】:Angular2 Routes with electron not working电子不工作的Angular2路线
【发布时间】:2017-05-10 13:55:24
【问题描述】:

我在 angular2 中的应用是一个又一个组件的全功能加载组件。当我尝试将它与电子一起使用时,一切都走下坡路。我一直在尝试遵循不同的教程,但它们对我不起作用。谁能指出我为什么这不起作用的方向。

应用内的index.html/

<html>
 <head>
  <meta charset="utf-8">
  <title>QuizzUmmah</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  </head>
<body>
 <h1>Index On</h1>
 <app></app>

 <script src="../node_modules/angular2/bundles/angular2-polyfills.js"></script>
 <script src="../build/common.js"></script>
 <script src="../build/angular2.js"></script>
 <script src="../build/app.js"></script>
</body>
</html>

app/start/内的App.ts

///<reference path="../../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from "angular2/platform/browser";
import { Component, provide } from "angular2/core";
import { ROUTER_DIRECTIVES, RouteConfig, Router, ROUTER_PROVIDERS } from 'angular2/router';
import { APP_BASE_HREF,HashLocationStrategy, Location, LocationStrategy } from '@angular/common';
import { Control } from 'angular2/common';
import { HomeComponent } from '../home/home.component';

@RouteConfig([
 { path: '/home', component: HomeComponent, name: 'HomeComponent' },
 { path: '/**', redirectTo: ['HomeComponent'] }
])

@Component({
  selector: "app",
  template:`<h1>Working</h1>
  <router-outlet></router-outlet>`,
  directives: [ROUTER_DIRECTIVES],
 })

 export class App {}

 bootstrap(App, [
  ROUTER_PROVIDERS,
  provide(APP_BASE_HREF, { useValue: '/' }),
  provide(LocationStrategy, { useClass: HashLocationStrategy })
 ]);

App/home 中的 HomeComponent

  import { Component} from '@angular/core';
  import { Router } from '@angular/router';

  @Component({
    selector: 'app-home',
    template:  `<h1>Home is working</h1>`,
   })
   export class HomeComponent{

   constructor(){}

   }

【问题讨论】:

  • 您的错误是什么?如果它与无法找到您的任何脚本(即 C://build/app.js)有关,请尝试将您的 更改为

标签: angular angular2-routing electron


【解决方案1】:

只需更改 index.html 文件的正文,如下所示。在正文中使用&lt;base&gt; 标签,不带“/”符号并尝试一下。

<body>
    <base href="">
    <h1>Index On</h1>
    <app></app>
    <script src=".....></script>
</body>

【讨论】:

  • 我在 部分添加了 标签。它解决了我的问题,即当我尝试使用带有 标记的相对链接时,我的单页应用程序总是显示白页。
  • 你的路由器阵列是什么..?请问你能用 发送那个吗
  • 我尝试了几种与“#/foo”“/foo”“foo”等的组合。都没有成功。但这是我的 SPA 嵌入 Electron 的特殊情况。使用空的 标签一切都很好,并且工作完美。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多