如何在Angular4中集成UI路由器。给定的示例似乎无法使用最新版本(https://ui-router.github.io/ng2/)
包装袋
"dependencies": {
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"ui-router-ng2": "^1.0.0-beta.1",
"zone.js": "^0.8.4"
}
app-routing.module.ts程序
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router'
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { UsersComponent } from './components/users/users.component';
/** Routing with ui-router */
import { UIRouter } from "ui-router-ng2";
let helloState = { name: 'dashboard', url: '/dashboard', component: DashboardComponent };
let aboutState = { name: 'users', url: '/users', component: UsersComponent };
@NgModule({
imports: [
UIRouter.forRoot({ states: [helloState, aboutState] })
],
exports: [
RouterModule
]
})
export class AppRoutingModule { }
“uirouter.forroot”上也有错误(forroot属性不存在)。有什么帮助或例子吗?
最佳答案
从“@uirouter/angular”:“^1.0.0-beta.6”,
您需要导入uiroutermodule,它包含forroot()
import { UIRouterModule } from "@uirouter/angular";
下面是一个官方演示应用程序,它显示了
https://ui-router.github.io/ng2/tutorial/helloworld
关于angular - Angular 4-UI路由器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43867450/