angular 4x 路由配置 报错后 一直改改改 没有效果,于是书生觉得代码理论上没问题了,重启了下服务,竟然没问题了。
这本来不算是问题,但是,有时候我们可能会在不是问题的问题上纠结很久。
错误代码: but '--allowJs' is not set.
错误来源: angular 4X router
上谷歌一会儿,有一个答案是 import { AppList } ...改
import * as Applist ...
这样确实不报错了,但是问题并没有解决。
报错图:
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: `
<h2>Home</h2>
<p>Get router Home page</p>
<button routerLink="/list">Go to List</button>
`
})
export class HomeComponent { }
list.component.ts
import { Component } from '@angular/core';
@Component({
template: `
<h2>List</h2>
<p>Get router list page</p>
<button routerLink="/">Go to home</button>
`
})
export class ListComponent { }
效果:
home listOK
附上angular中文路由链接: https://www.angular.cn/docs/ts/latest/guide/router.html
--END--
网友评论