Route
Framework: Vue.js Route
Categories:
Generate route link
<router-link to="/">Go to Home</router-link>
<router-link to="/about">Go to About</router-link>
URL History modes
import { createRouter, createWebHashHistory } from 'vue-router'
const router = createRouter({
// Hash Mode
history: createWebHashHistory(),
// HTML5 Mode
history: createWebHistory(),
// Memory mode
history: createMemoryHistory(),
routes: [
//...
],
})
Rewrite server configuration
Nginx
location / {
try_files $uri $uri/ /index.html;
}
Node.js
const http = require('http')
const fs = require('fs')
const httpPort = 80
http
.createServer((req, res) => {
fs.readFile('index.html', 'utf-8', (err, content) => {
if (err) {
console.log('We cannot open "index.html" file.')
}
res.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8',
})
res.end(content)
})
})
.listen(httpPort, () => {
console.log('Server listening on: http://localhost:%s', httpPort)
})