When vue-cli3.0 is configured with multiple pages, the route cannot be found after local refresh. How to configure it?

found a new vue-cli scaffolding with multi-page configuration items. Try to configure the document . You can visit each page, but when you refresh, the route to the corresponding page cannot be found. The code is as follows

.
// vue.config.js
module.exports = {
  baseUrl: process.env.NODE_ENV === "production"
    ? "/ems/"
    : "/ems/",
  pages: {
    admin: {
      entry: "src/views/admin/main.js",
      template: "public/admin.html",
      filename: "admin/index.html",
    },
    school: {
      entry: "src/views/school/main.js",
      template: "public/school.html",
      filename: "school/index.html",
    }
  }  
}

// admin.routes.js
import Vue from "vue"
import Router from "vue-router"
import Home from "@/views/admin/Home.vue"
import Layout from "@/components/layout-admin"

Vue.use(Router)

const routes = [
  {
    path: "/",
    redirect: {name: "admin"},
  },
  {
    path: "/admin",
    name: "admin",
    component: Layout,
    redirect: {name: "home"},
    children: [
      {
        path: "home",
        name: "home",
        component: Home
      },
      {
        path: "about",
        name: "about",
        component: () => import("./../views/admin/About.vue")
      }
    ]
  }  
]

export default new Router({
  mode: "history",
  base: process.env.BASE_URL,
  routes
})

it is possible to access / ems/admin by accessing / ems/admin/home route, but it is impossible to access / ems/admin/home directly.

Sep.16,2021

const baseUrl ='/ ems/';

module.exports = {
baseUrl: baseUrl,
pages: {

admin: {
  entry: 'src/main.js',
  template: 'public/index.html',
  filename: 'admin/index.html',
},
school: {
  entry: 'src/main.js',
  template: 'public/index.html',
  filename: 'school/index.html',
},

},
devServer: {

before: function(app) {
  const base = baseUrl.replace(/\/+$/, ''); // 
  app.get(`${base}/:page/*`, function(req, res, next) {
    if (['admin', 'school'].includes(req.params.page)) {
      //  /<base>/<page>/*  /<base>/<page>/
      req.url = `${base}/${req.params.page}/`;
      next('route');
    } else {
      next();
    }
  });
},

},
};


the server is not configured. You said yourself it is possible to access / ems/admin/home through access / ems/admin routing, but direct access to / ems/admin/home is not accessible

the reason is that when you visit directly, you initiate a get request to the backend. The backend is not configured for routing. You need to configure that all routes are returned to your corresponding html file.

ide/essentials/history-mode.html-sharp%E5%90%8E%E7%AB%AF%E9%85%8D%E7%BD%AE%E4%BE%8B%E5%AD%90" rel=" nofollow noreferrer "> https://router.vuejs.org/zh/g.


set historyApiFallback

  

A point to a configuration problem during local development and debugging

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b42840-2c614.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b42840-2c614.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?