将路由名称添加到数组

Add Route names to array

我可以将路由添加到数组而不是将 <a href> 用作字符串吗?

在这个例子中,我正在为 update-building 创建一个 link 并添加 buildingId 作为参数。

有没有办法使用 'update-building' 的路由名称?

 axios
      .get("https://localhost:44349/api/Building/List", headers)
      .then(response => {
        response.data.forEach(el => {

          this.dataset.push([
              el.city, 
              el.street, 
              el.number, 
              el.projectName, 
             `<a href='#/update-building/${el.buildingId}'>update</a>`, // use route name instead this
             ]);
        });

我的路由器文件:

 {
      path: '/update-building:buildingId',
      name: 'UpdateBuilding',
      component: UpdateBuilding,
      props: true,
      params: null,
      meta: {
        requiresAuth: true
      }
    },

基于nemesv是答案!

axios
      .get("https://localhost:44349/api/Building/List", headers)
      .then(response => {
        response.data.forEach(el => {

         var url = this.$router.resolve({ name: 'UpdateBuilding', params: { buildingId: el.buildingId }}).href
          this.dataset.push([
              el.city, 
              el.street, 
              el.number, 
              el.projectName, 
             `<a href='#/${url}/${el.buildingId}'>update</a>`, 
             ]);
    });