Vue 2.1中文件的虚荣URL

时间:2017-03-14 14:52:20

标签: vue.js vuejs2 vue-router

通过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中进行。

1 个答案:

答案 0 :(得分:1)

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