I
I
Iceling2019-03-31 17:29:31
JavaScript
Iceling, 2019-03-31 17:29:31

How to remove slash at the end of URL in Nuxt application (SPA mode)?

I use Nuxt.js in SPA mode in the project.
I ran into a problem that when deploying a site on a server (Apache), if you go to one of the internal pages directly, the images are not loaded (the paths do not converge).
As I found out, the problem is that the server treats the URL as a link to a directory, not a file, which adds a slash. And the application, in turn, loads the file as if the link to the page is a file. (in fact, this is really the directory in which the index.html with the scripts is located).
Here is the main page - 4dea.ru/works/TEST/spc/
If you follow the link (button in the "Marine structures" section) to 4dea.ru/works/TEST/spc/morskie-konstrukciithen everything will be in order (as I understand it, because then the server regards the current file as if it were in the root folder). However, if this page is the same (with marine structures), then a slash will certainly be added to it and spoil everything (in the header and below, in the gallery, pictures are not loaded)
I tried to prohibit adding a slash to .htaccess (DirectorySlash Off), but then the server will process the request can not.
It is noteworthy that on the Node.js locale, the server does not substitute a slash, and at the same time everything works well.
Now .htaccess has been cleared for now.
I would like to know how to solve this problem (without resorting to absolute paths for images)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Iceling, 2019-03-31
@Iceling

Found two solutions:
1. You can set href="/image.png" instead of href="image.png", then the absolute path to the image will be specified from all pages and everything will work as it should. However, this option will not work if the application is not located in the root directory of the site.
2. Load from assets via href="@/assets/image.png". For styles and dynamic paths, you can use:
Good luck to all :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question