首页 > 其他 > 详细

angularcli 第八篇(router 路由)

时间:2018-09-03 18:47:42      阅读:289      评论:0      收藏:0      [点我收藏+]

页面有两个按钮(test1、test2),点击这两个按钮,跳转相应页面~

注:创建一个带路由模块的项目:ng new project --routing 

 (下面针对新建项目时没有带路由,后边再来新建路由)

 

1、新建两个页面 test1、test2(html、css、ts):       ng g component test1

2、新建路由模块app.routing.ts                                   ng generate module app-routing --flat --module=app

  • 在 app.routing.ts 中 import 根组件、子组件路由组件等;
  • 在 app.routing.ts 中 编写路由路径const routes;

技术分享图片

 

3、在app.modules.ts中:

  • 导入根组件路由组件,以及相应子组件(test1、test2)   import { AppRoutingModules } from "./app/routing";
  • 在 import:[......]中添加相应路由组件(routing)
  • 初始化路由器imports: [ RouterModule.forRoot(routes) ],  基于浏览器的当前 URL 执行首次导航

技术分享图片

 

 3、在app.component.ts中添加相应的按钮,以及路由路径

技术分享图片

 

angularcli 第八篇(router 路由)

原文:https://www.cnblogs.com/luwanying/p/9580021.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!