Answer the question
In order to leave comments, you need to log in
How to combine Vue and Express in SPA?
There is a node server with express, there is vue with vue-router and several paths in it.
Server code:
// Подключение библиотек
const express = require('express');
const mysql = require('mysql2');
const path = require('path');
const history = require('connect-history-api-fallback');
// Конфигурации
const config = require('./config/config.js')
const app = express();
// парсинг запросов
app.use(express.json())
// статические файлы в корне директории сервера
// app.use(express.static('public/dist'))
app.use(express.static(config.static.dirVue))
app.use(history());
// страницы html для рендеринга
const page = {
'index': path.resolve(config.static.dirVue, 'index.html')
}
// запустить сервер
app.listen(process.env.PORT || config.server.port, () => {
console.log(`server start on ${config.server.port} port`);
console.log(`127.0.0.1:${config.server.port}`);
})
app.get('*', (req, res) => {
// console.log(req.params);
res.sendFile(page.index);
})
Answer the question
In order to leave comments, you need to log in
Documentation and guides on the same topic will help you: https://expressjs.com/ru/guide/routing.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question