angular 中使用“单页应用”的步骤
- 定义“路由词典”--- [{URL - 组件},{URL - 组件}]
let routes = [
{path: 'index', component: IndexComponent},
..........
{path: 'ucenter', component: UserCenterComponent},
]
- 在根组件中注册路由词典
imports:[BrowserModule, RouterModule.forRoot(routes)]
- 创建路由组件挂载点 -- 称为“路由出口”
<router-outlet></router-outlet>
- 访问测试
http:
route:
route:路径、路线、路由,有两部分:目标地址 + 处理过程
router:
router:路由器、内部包含着路由词典
注意
- 路由词典中的路由地址不能以/开头或结尾,但中间可以包含/
- 路由词典中可以指定一个默认首页地址:{path:"", component:...}
- 路由词典中每个路由中要么指定Component(由那个组件提供内容),要么指定redirectTo(重定向到另一个路由地址)
- 路由词典中可以指定一个匹配任意地址的地址:'** ' , 注意改地址只能用于整个路由词典的最后一个!!