When a nuxtjs app in spa mode is built, the assets are referenced at /_nuxt/vendor.a0f2fda15695e202a186.js
in index.html
.
Is it possible to reference to those files with a relative url (without the first slash)?
(something like <script type="text/javascript" src="_nuxt/vendor.a0f2fda15695e202a186.js"></script>
)
To link pages using relative URL in HTML, use the <a> tag with href attribute. Relative URL is used to add a link to a page on the website. For example, /contact, /about_team, etc.
A relative URL is a URL that only includes the path. The path is everything that comes after the domain, including the directory and slug. Because relative URLs don't include the entire URL structure, it is assumed that when linking a relative URL, it uses the same protocol, subdomain and domain as the page it's on.
Relative URLs are more convenient because they are shorter and often more portable. However, you can use them only to reference links on the same server as the page that contains them.
An absolute URL contains all the information necessary to locate a resource. A relative URL locates a resource using an absolute URL as a starting point. In effect, the "complete URL" of the target is specified by concatenating the absolute and relative URLs.
Probably not.
See https://github.com/nuxt/nuxt.js/issues/1380
The reason you want a "relative path" to your assets is because your SPA (or your assets) are not at the root directory of your domain. For example:
Your SPA is NOT at https://my-domain.com/
But at https://my-domain.com/my-app/
Go to nuxt.config.js
and edit the following properties.
build: {
// Set the absolute path where the assets are.
// https://nuxtjs.org/api/configuration-build#publicpath
publicPath: 'https://my-domain.com/my-app/',
},
router: {
// Set the "Base" of the router.
// https://router.vuejs.org/en/api/options.html#base
base: '/my-app/'
},
link: [
// Do this if you have files that are located at /static/
// https://nuxtjs.org/guide/assets#static
{
rel: 'stylesheet',
type: 'text/css',
href: '/my-app/myStyleSheet.css'
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With