docs: easier Netlify setup for history mode (#6093)

Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
This commit is contained in:
Maurici Abad Gutierrez
2020-12-18 10:21:04 +01:00
committed by GitHub
parent 9e32481d4c
commit fe0fa6718e
+19 -3
View File
@@ -169,15 +169,31 @@ Commit both the `.gitlab-ci.yml` and `vue.config.js` files before pushing to you
Also checkout [vue-cli-plugin-netlify-lambda](https://github.com/netlify/vue-cli-plugin-netlify-lambda).
In order to receive direct hits using `history mode` on Vue Router, you need to create a file called `_redirects` under `/public` with the following content:
#### Use history mode on Vue Router
In order to receive direct hits using `history mode` on Vue Router, you need to redirect all trafic to the `/index.html` file.
> More information on [Netlify redirects documentation](https://docs.netlify.com/routing/redirects/rewrites-proxies/#history-pushstate-and-single-page-apps).
##### Recomended method
Create a file called `netlify.toml` in the root fo your repository wit the following content:
```toml
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
```
##### Alternative method
Create a file called `_redirects` under `/public` with the following content:
```
# Netlify settings for single-page application
/* /index.html 200
```
More information on [Netlify redirects documentation](https://www.netlify.com/docs/redirects/#history-pushstate-and-single-page-apps).
If you are using [@vue/cli-plugin-pwa](https://cli.vuejs.org/core-plugins/pwa.html#vue-cli-plugin-pwa) make sure to exclude the `_redirects` file from being cached by the service worker.
To do so, add the following to your `vue.config.js`:
```javascript