栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

带有BrowserRouter / browserHistory的React-router在刷新时不起作用

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

带有BrowserRouter / browserHistory的React-router在刷新时不起作用

您在路线中提到的第一件事是具有path的home组件

/home
。所以你需要参观
http://localhost:8080/home
。另外,如果您尝试直接访问此网址,则由于使用,它也会给您此错误
browserHistory
。如果您希望可以在
hashHistory
HashRouter
react-
router
v4中使用,则需要访问
http://localhost:8080/#/home
。如果要继续使用
browserHistory
BrowserRouter
在react-
router v4中使用,则需要
historyApiFallback: true
在webpack中添加

var webpack = require('webpack');var path = require('path');var BUILD_DIR = path.resolve(__dirname, 'src/client/public');var APP_DIR = path.resolve(__dirname, 'src/client/app');var config = {    entry: [        APP_DIR + '/config/routes.jsx',        'webpack/hot/dev-server',        'webpack-dev-server/client?http://localhost:8080'    ],  output: {    publicPath: 'http://localhost:8080/src/client/public/'  },  devServer: {    historyApiFallback: true  },  module : {    loaders : [      {        test: /.jsx?$/,        loader: 'babel-loader',        include: APP_DIR,        exclude: /node_modules/,        query: { presets: ['es2015']        }      },      {        test: /.scss$/,        loaders: [ 'style', 'css', 'sass' ]      },       {        test: /.json$/,         loader: "json-loader"     }    ]  }};module.exports = config;


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/409706.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号