小编ten*_*tis的帖子

错误:useHref() 只能在 <Router> 组件的上下文中使用。当我直接将 url 设置为 localhost:3000/experiences 时它会起作用

我有一个导航栏,当路线单击时发生变化时,它会在每条路线中呈现。

./components/navbar.jsx

import React, { Component } from 'react';
import '../App.css';
import { Link } from 'react-router-dom';



class Navbar extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    render() {
        return (
            <div id = 'navbar'>

                <div className='name-head'>
                    My Name
                </div>
            
            
                <div id = 'nav-links-container'>
                    
                    <Link to='/experiences'>
                        <div className = 'nav-links'>
                            Experiences
                        </div>
                    </Link>

                    <div className = 'nav-links'>
                        Projects
                    </div>

                    <div className = 'nav-links'>
                        Skills
                    </div>

                    <div className = 'nav-links'>
                        Resume
                    </div>

                </div>
                
            </div>
        );
    }
}

export default …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router react-router-dom

94
推荐指数
5
解决办法
13万
查看次数

标签 统计

react-router ×1

react-router-dom ×1

reactjs ×1