如何通过 cdn 正确包含 vue-router 以使历史模式正常工作?

How to correctly include vue-router via cdn to make history mode working?

我在 html 文档中包含这样的脚本:

    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

在 main.js 中,当我写 mode: 'history' 时,什么也没有出现:

const routes = [
  {path: '/', name: 'blank', component: BlankPage},
  {path: '/directory1', name: 'directory1', component: Directory1},
  {path: '/directory2', name: 'directory2', component: Directory2},
  {path: '/directory3', name: 'directory3', component: Directory3},
]

const router = new VueRouter({
  routes,
  mode: 'history'
})

const app = new Vue({
  router,
}).$mount('#app')

当我删除 mode:'history' 网页时出现。如何处理?

历史模式需要一些服务器,例如开发服务器。所以我在 gulp 的帮助下创建了一个简单的开发服务器。 gulpfile.js:

var gulp = require('gulp'),
  connect = require('gulp-connect');
 
gulp.task('webserver', function() {
  connect.server({
    fallback: 'table.html'
  });
});
 
gulp.task('default', gulp.series('webserver'));

现在可以使用历史记录模式了。如果有人知道这是为什么,请告诉我!