vue-router是对浏览器BOM对象里的history的封装。
路由类型
- 动态路由匹配
- 嵌套路由
- 编程式路由
- 命名路由和命名视图
动态路由匹配
在路由路径里添加“/:参数名”
path: '/goods/:goodsId'
组件里获取参数使用
{
{
$route.params.goodsId}}
嵌套路由
场景:页面中需要使用二级子菜单。如个人中心一级菜单下,有个人资料、我的收藏、购物车等二级菜单。
在路由里使用children
export default new Router({
routes: [
{
path: '/goods',
name: 'GoodsList',
component