通过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中进行。
答案 0 :(得分:1)
我不认为这可以开箱即用vue-router - 它希望重定向值是另一个客户端路由,而不是服务器端URL。我认为您最好的选择是在beforeEnter
路由上使用/rules
后卫将(使用window.location
)重定向到网址。或者,您可以让/rules
路由返回一个在iframe中显示pdf的组件。