D
D
danilr2021-07-30 00:19:03
Vue.js
danilr, 2021-07-30 00:19:03

What server settings are needed for SPA?

I have a Vue SPA application using mode: 'history' in VueRouter. Locally, everything goes well on "other villages". I uploaded it to the hosting, it gives a 404 error when switching to any other route (/about)

How can I make the hosting always give me my only page when switching to other routes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
danilr, 2021-07-30
@danilr

Here is the documentation for VueRouter just for my question
https://router.vuejs.org/guide/essentials/history-...
Add to .htaccess to redirect to index.html

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

S
Samuello, 2021-07-30
@Samuello

If you are using Laravel, you can route all requests through routes:

Route::get('{any}', function() {
  return view('spa');
})->where('any', '.*');

In this case, you can register other routes at a higher level:
Route::get('/api/v1/products', function() {
  return 'some api handler...';
});

Route::get('{any}', function() {
  return view('spa');
})->where('any', '.*');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question