首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >汇总插件服务历史API回退不起作用

汇总插件服务历史API回退不起作用
EN

Stack Overflow用户
提问于 2019-09-04 00:56:33
回答 1查看 832关注 0票数 1

我正在为我的svelte应用程序使用rollup。我从npm到我们的historyApiFallback安装了rollup-plugin-serve包,这样我就可以在我的spa应用程序中提供任何url。

https://github.com/thgh/rollup-plugin-serve

我的配置如下所示:

代码语言:javascript
运行
复制
import serve from 'rollup-plugin-serve'

serve({
   contentBase: 'dist',
   port: 5000,
   historyApiFallback: true,
   historyApiFallback: 'index.html'
}),

这是我的完整rollup.config.js

代码语言:javascript
运行
复制
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import postcss from 'rollup-plugin-postcss';
import resolve from 'rollup-plugin-node-resolve';
import svelte from 'rollup-plugin-svelte';
import {terser} from 'rollup-plugin-terser';
import svelte_preprocess_postcss from 'svelte-preprocess-postcss';
import serve from 'rollup-plugin-serve'

const production = !process.env.ROLLUP_WATCH;
export default {
   input: 'src/main.js',
   output: {
      format: 'iife',
      sourcemap: true,
      name: 'app',
      file: 'dist/main.js',
   },
   plugins: [
      svelte({
         dev: !production,
         preprocess: {
            style: svelte_preprocess_postcss(),
         },
         css: css => {
            css.write('dist/components.css');
         },
      }),
      resolve(),
      commonjs(),
      postcss({
         extract: true,
      }),
      serve({
         contentBase: 'dist',
         host: 'localhost',
         port: 5000,
         historyApiFallback: true
      }),
      !production && livereload('dist'),
      production && terser(),
   ],
};

但是这个代码不起作用。当我为localhost:5000/solutions/technic服务时,我仍然得到404not Found错误。

有什么好主意吗?

EN

回答 1

Stack Overflow用户

发布于 2019-09-04 01:28:35

尝试使用'/index.html'而不是'index.html',例如:

代码语言:javascript
运行
复制
serve({
   contentBase: 'dist',
   port: 5000,
   historyApiFallback: '/index.html'
}),

或者使用historyApiFallback: true (/index.html is used as default):

代码语言:javascript
运行
复制
serve({
   contentBase: 'dist',
   port: 5000,
   historyApiFallback: true
}),
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57775945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档