Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested routes breaks the static path

My css is placed inside the static directory.

html:

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

And I have nested routes

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

When I am outside of the nested route, the static file is found. But, when I navigate to user/user_21/feeds, Vue can't find the css.

The working css:

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

Turns into a wrong static path:

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

How can I solve this?

like image 240
Kakar Avatar asked Jul 16 '17 22:07

Kakar


1 Answers

What if you link an absolute url for the css begining with a /?

 <link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css">
like image 145
François Romain Avatar answered Nov 14 '22 01:11

François Romain