【问题标题】:Nested routes breaks the static path嵌套路由打破了静态路径
【发布时间】:2017-07-16 22:01:41
【问题描述】:

我的 css 放在静态目录中。

html:

<html>
  <head>
    <link rel="stylesheet" href="static/font-awesome/css/font-awesome.min.css">
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

我有嵌套路线

const routes = [
    {
        path: '/user/:id', component: Profile,
        children: [
            {
                path: 'feeds',
                component: ProfileFeeds
            },
            {
                path: 'photos',
                component: ProfilePhotos
            },
        ]
    },
    ... some other routes... ,
];

当我在嵌套路由之外时,会找到静态文件。但是,当我导航到 user/user_21/feeds 时,Vue 找不到 css。

工作的 css:

http://localhost:8080/static/font-awesome/css/font-awesome.min.css

变成错误的静态路径:

http://localhost:8080/user/static/font-awesome/css/font-awesome.min.css

我该如何解决这个问题?

【问题讨论】:

    标签: vue.js vuejs2 vue-router


    【解决方案1】:

    如果您链接以/ 开头的css 的绝对URL 怎么办?

     <link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css">
    

    【讨论】:

    • 是的,这行得通。谢谢你。你能告诉我为什么相对路径不起作用吗?
    • 相对路径可能是相对于当前url的。
    • 您好,不是完全相同的情况,请您查看一下吗? stackoverflow.com/questions/55156339/…
    猜你喜欢
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    • 2021-12-02
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多