Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue.js route problem on my server - does not work

Tags:

vue.js

I have routes, like this:

/about
/experience

When i click localhost/about , localhost/experience its working.

But when i upload the files to the my server like test.com, if i try to go test.com/experience its not working. its giving an 404 error. enter image description here

But if i go to the pages from the homepage, its working. What is the problem?

like image 420
Hakan Gundogan Avatar asked Dec 04 '25 13:12

Hakan Gundogan


2 Answers

I solved it with htaccess

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
    </IfModule>
like image 147
Hakan Gundogan Avatar answered Dec 07 '25 03:12

Hakan Gundogan


Your server is not configured to rewrite missing files (HTTP 404 errors) to your /index.html If you're using Nginx, this can be achieved like this:

⋮

location / {
  try_files $uri @rewrite;
}

location @rewrite {
  rewrite ^(.*)$ /index.html last;
}

If you can not control your web server configuration - you will need to switch from history to hash mode in the Vue-Router settings.

like image 35
IVO GELOV Avatar answered Dec 07 '25 03:12

IVO GELOV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!