React-Router-dom导航链接未呈现

时间:2019-06-26 17:33:30

标签: reactjs webpack webpack-dev-server react-router-dom

我正在尝试使用react-router-dom构建导航,但是当我运行build时,Navlink或react-router-dom中的任何内容都不会呈现。

     My file webpack.config

` module.exports = {
        entry: ['./src/index.js'],
        output: {
            path: __dirname + '/dist',
            filename: 'bundle.js'

    },
    devServer: {
            historyApiFallback: true,
          },
    `



     My navigation.js file
`import { NavLink } from 'react-router-dom';



    const Navbar  = () =>{

          return (

         <div><ul><li>
          <NavLink to "/work">Work</NavLink></li></ul></div>
          );
      }
      export default Navbar;`

1 个答案:

答案 0 :(得分:1)

您需要在<NavLink>元素内添加一些东西。

请参见documentation,其中提供了以下示例:

import { NavLink } from 'react-router-dom'

<NavLink to="/about">About</NavLink>