# vue3 中 vue-router 获取路由完整 url
# 1. 介绍
vue3 中,获取指定路由的完整 URL
# 2. 示例
hash 路由:
/*
routeLocation
{
href: "#/home?name=zhangsan&age=18"
}
*/
const routeLocation = this.$router.resolve({ name: 'Home', query: { name: 'zhangsan', age: 18 } });
const routeFullPath = routeLocation.href;
/*
window.location
{
origin : "http://localhost:8088"
pathname : "/"
}
*/
console.log(window.location);
const { origin, pathname } = window.location;
const url = `${origin}${pathname}${routeFullPath}`;
// http://localhost:8088/#/home?name=zhangsan&age=18
console.log(url);
上一篇: 下一篇:
本章目录