gpt4 book ai didi

javascript - Uncaught ReferenceError : Link is not defined React

转载 作者:行者123 更新时间:2023-11-29 14:42:37 25 4
gpt4 key购买 nike

我将 react 0.14.7 与 webpack 1.12.13 一起使用,但出现以下错误:

Uncaught ReferenceError: Link is not defined

此错误发生在浏览器中,所有内容都可以正常编译。

import React from 'react'
import { Link } from 'react-router'

export default React.createClass({
render() {
return <Link {...this.props} activeClassName="active"/>
}
})

webpack.config

var webpack = require('webpack')

module.exports = {
entry: './src/client/js/index.js',

output: {
path: 'public',
filename: 'bundle.js',
publicPath: '/'
},

resolve: {
extensions: ['', '.js', '.jsx']
},

plugins: process.env.NODE_ENV === 'production' ? [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
] : [],

module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' },
{ test: /\.scss$/, loaders: ['style', 'css', 'sass']}
]
},

}

再多一点,让我更加困惑的是,我安慰了 react-router,但那里什么也没有:

import router from 'react-router'
console.info(router); //undefined

最佳答案

改用react-router-dom


从'react-router-dom'导入{链接}
...

参见 react-router-dom在 npm 上。

关于javascript - Uncaught ReferenceError : Link is not defined React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36750522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com