The Code
I have a Vue App with this structures :
- public
- img
- logo.png
- img
- src
And i have this router.js
const router = new Router({
mode: "history",
routes: [
{
path: '/',
redirect: 'dashboard',
component: UITemplate,
children: [
{path: '/dashboard', name: 'dashboard', component: () => import('/views/Dashboard.vue')},
{path: '/admin/role', name: 'role', component: () => import('/views/Role.vue')},
]
}
]
})
And this vue.config.js
module.exports = {
...
publicPath: '/'
...
}
The Problem
Let's say i want to link an src
to an img
in UITemplate component. It looks like this
<img :src="/img/brand/logo.png" />
If i try this on localhost:8080/dashboard
, the image is perfectly shown.
But when i try on localhost:8080/admin/role
, the image is not showing.
I looked up in Network Panel and it tries to find the file in this url :
localhost:8080/admin/role/img/logo.png
So how to perfectly use the publicPath in Vue so the publicPath will always start from the public folder (without adding /admin/role)? I tried another solutions by adding base
to Router, publicPath
in webpack.config.js
, but it's still not working