Solve the problem that vue cannot copy dynamic address in ios wechat “Copy link”

This is perfectly fine on Android, but it’s completely dead on the iPhone. Because ios wechat has a # recognition problem in VUE routing.

My solution was to re-concatenate the project address when initially entering the project and then redirect to the concatenated address.

Obtain the route address before #, then manually add our # and the current project address suffix:

Location: write in the beforeEach function of router. Js

Capture the address

// Redirection function, in order to solve the ios wechat replication link function cannot be copied to the dynamic route problem
// Get the first part of the address
 var replaceUrl = window.location.href.split(The '#') [0] + The '#' + to.path;
 var index = 0; // Index initialization
 // Concatenate parameters for the replaceUrl
 for (var i in to.query) {
   // Check if it is equal to the first argument
   if (index == 0) {
     // Add "? "to the first parameter of the address. No.
     replaceUrl += '? ' + i + '=' + to.query[i]
   } else {
     // Concatenate address is not the first parameter, add "&"
     replaceUrl += '&' + i + '=' + to.query[i]
   }
   index++; / / index + +
 }
Copy the code

Redirect redirect

window.location.replace(replaceUrl); // Redirect redirect
Copy the code

All the code

router.beforeEach((to, from, next) = > {	  
next();
// Redirection function, in order to solve the ios wechat replication link function cannot be copied to the dynamic route problem
// Get the first part of the address
var replaceUrl = window.location.href.split(The '#') [0] + The '#' + to.path;
var index = 0; // Index initialization
// Concatenate parameters for the replaceUrl
for (var i in to.query) {
  // Check if it is equal to the first argument
  if (index == 0) {
    // Add "? "to the first parameter of the address. No.
    replaceUrl += '? ' + i + '=' + to.query[i]
  } else {
    // Concatenate address is not the first parameter, add "&"
    replaceUrl += '&' + i + '=' + to.query[i]
  }
  index++; / / index + +
}
// console.log('test20190117:' + to.meta.title, replaceUrl);
window.location.replace(replaceUrl); // Redirect redirect
// Redirection ------end
});
Copy the code

~ ~

Good luck, problem solved

~ ~

Copyright notice: This article is an original article BY CSDN blogger “Cen Agricultural Agriculture – Shenzhen”. It follows CC 4.0 BY-SA copyright agreement. Please attach the source link of the original article and this statement. Original link: blog.csdn.net/qq_37235823…