Vue 2.1 中文件的个性化 URL
Vanity urls for files in Vue 2.1
阅读 Vue 路由器 docs 这看起来应该很简单,但我无法让它工作。
首先我尝试使用S3中的文件
{
path: '/rules',
redirect: 'https://s3.amazonaws.com/itsclarke/vue-project/pdfs/rules.pdf'
}
这导致重定向附加到 localhost:8080/#
,所以我得到 localhost:8080/#/https://s3.amazonaws.com/...
还尝试对 static
文件夹使用相同的方法:
{
path: '/rules',
redirect: '../../static/rules.pdf'
}
这使路径保持相对,但没有显示 pdf,而是将我带到了 localhost:8080/#/static/rules.pdf
,这不是路径。 localhost:8080/static/rules.pdf
是我需要的。这也需要使用hash
模式。
使用别名模式也没有太大帮助,因为我没有这些文件的组件。我知道这些重定向可以在服务器级别关闭,但我想在 Vue Router 中进行。
我不认为 vue-router 开箱即用 - 它期望重定向值是另一个客户端路由,而不是服务器端 url。我认为你最好的选择是在你的 /rules
路由上使用 beforeEnter
守卫来重定向(使用 window.location
)到 url。或者,您可以让 /rules
路由 return 一个在 iframe 中显示 pdf 的组件。
阅读 Vue 路由器 docs 这看起来应该很简单,但我无法让它工作。
首先我尝试使用S3中的文件
{
path: '/rules',
redirect: 'https://s3.amazonaws.com/itsclarke/vue-project/pdfs/rules.pdf'
}
这导致重定向附加到 localhost:8080/#
,所以我得到 localhost:8080/#/https://s3.amazonaws.com/...
还尝试对 static
文件夹使用相同的方法:
{
path: '/rules',
redirect: '../../static/rules.pdf'
}
这使路径保持相对,但没有显示 pdf,而是将我带到了 localhost:8080/#/static/rules.pdf
,这不是路径。 localhost:8080/static/rules.pdf
是我需要的。这也需要使用hash
模式。
使用别名模式也没有太大帮助,因为我没有这些文件的组件。我知道这些重定向可以在服务器级别关闭,但我想在 Vue Router 中进行。
我不认为 vue-router 开箱即用 - 它期望重定向值是另一个客户端路由,而不是服务器端 url。我认为你最好的选择是在你的 /rules
路由上使用 beforeEnter
守卫来重定向(使用 window.location
)到 url。或者,您可以让 /rules
路由 return 一个在 iframe 中显示 pdf 的组件。