angular 4x 路由配置 AND but '--allowJs' is not set 的解决方案

angular 4x 路由配置 报错后 一直改改改 没有效果,于是书生觉得代码理论上没问题了,重启了下服务,竟然没问题了。

这本来不算是问题,但是,有时候我们可能会在不是问题的问题上纠结很久。

错误代码: but '--allowJs' is not set.

错误来源: angular 4X router

上谷歌一会儿,有一个答案是 import { AppList } ...改

import * as Applist ... 

这样确实不报错了,但是问题并没有解决。

报错图:

angular 4x 路由配置 AND but '--allowJs' is not set 的解决方案_第1张图片
Error message

上配置代码:

app.module.ts
import { BrowserModule } from '@angular/platform-browser'
import { NgModule } from '@angular/core'
import { RouterModule, Routes } from '@angular/router'

import { AppComponent } from './app.component'
import { ListComponent } from './list.component'
import { HomeComponent } from './home.component'

const appRoutes: Routes = [
  {
    path: 'list',
    component: ListComponent
  },
  {
    path: 'home',
    component: HomeComponent
  },
  {
    path: '',
    redirectTo: '/home',
    pathMatch: 'full'
  }
]

@NgModule({
  declarations: [
    AppComponent,
    ListComponent,
    HomeComponent
  ],
  imports: [
    RouterModule.forRoot(appRoutes),
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

home.component.ts
import { Component } from '@angular/core';
@Component({
  template: `
    

Home

Get router Home page

` }) export class HomeComponent { }
list.component.ts
import { Component } from '@angular/core';
@Component({
  template: `
    

List

Get router list page

` }) export class ListComponent { }

效果:

angular 4x 路由配置 AND but '--allowJs' is not set 的解决方案_第2张图片
home
angular 4x 路由配置 AND but '--allowJs' is not set 的解决方案_第3张图片
list

OK

附上angular中文路由链接: https://www.angular.cn/docs/ts/latest/guide/router.html

--END--

你可能感兴趣的:(angular 4x 路由配置 AND but '--allowJs' is not set 的解决方案)