Angular 添加位置5
如何在路由上配置locationProvider?我用的是角度5 我没有找到关于它的文档Angular 添加位置5,angular,angular2-routing,Angular,Angular2 Routing,如何在路由上配置locationProvider?我用的是角度5 我没有找到关于它的文档 const appRoutes = [ {path: '', redirectTo: '/example/example', pathMatch: 'full'}, { path: 'example', children: [ {path: ':example', component: example} ] } ]; @NgModule({ imports: [
const appRoutes = [
{path: '', redirectTo: '/example/example', pathMatch: 'full'},
{
path: 'example', children: [
{path: ':example', component: example}
]
}
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{
// enableTracing: true, // <-- debugging purposes only
})
],
exports: [
RouterModule
],
})
export class AppRoutingModule {
}
常量批准=[
{路径:'',重定向到:'/example/example',路径匹配:'full'},
{
路径:“示例”,子项:[
{路径:':example',组件:example}
]
}
];
@NGD模块({
进口:[
RouterModule.forRoot(
批准,
{
//enableTracing:true,//locationProvider用于AngularJS,但不用于Angular2/5
您必须使用路由器、RouterModule和RouterOutlet。有关更多信息,请参阅
例如,要更改可以在JS中使用的位置
this.router.navigate(['/home']);
或者在HTML中
<button [routerLink]="['/home']">Home</button>
主页
您还可以捕获一些事件,如“NavigationStart”、“NavigationEnd”、“NavigationError”只需使用-
<a routerLink="/home">Home</a>
主页
这将导航到主组件我认为您对Angular 5是新手。Angular JS和Angular完全不同。
Angular 5,Angular 2/4/5中没有可用的位置提供程序
请使用以下文档
用户路由器链接如下
从模板
<a [routerLink]="['/user/bob']" [queryParams]="{debug: true}" fragment="education">
link to user component
</a>
现在还不清楚你所展示的是什么问题。答案可能是
this.router.navigate(['/home']);