动态路由

135 阅读1分钟

在某些情况下,一个页面的path路径可能是不确定的,比如我们进入用户界面时,希望是如下路径:/user/aaa或者/user/bbb,除了有前面的/user外,后面还跟上后台给的用户id

1.在router目录下给指定路由配置动态模式, {

path: '/About/:userid',
name: 'About',
component: About

}

2.把后台给的id数据拼接到url里

router-link :to="'/About/' + id"跳转router-link

image.png

image.png

3.在拼接的url组件里可拿到拼接的数据

image.png