Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142382

After refresh route display first route

$
0
0

I have this routing system

constructor(props){
    super(props);
    this.state = {
        url: window.location.pathname,
        about: '',
        user: '',
        userPath: ''
    }


}

componentDidMount(){
    this.setState({
        about: this.state.url + '/about',
        user: this.state.url + '/user/1',
        userPath: this.state.url + '/user/:id',

    })

}

Link and view is generated here

//generated link
                    <ul>
                        <li>
                             <NavLink exact activeClassName="active" to={this.state.url}>Home</NavLink>
                        </li>
                        <li>
                            <NavLink activeClassName="active" to={this.state.about}>About</NavLink>

                        </li>
                        <li>
                            <NavLink activeClassName="active" to={this.state.user}>User</NavLink>
                        </li>
                    </ul>
//render view
                    <Route exact path={this.state.url} component={Home} />
                    <Route path={this.state.about} component={About} />
                    <Route path={this.state.userPath} component={User} />

It works correctly but all the times I have a problem with url address. The biggest is that I go to any route (it works) and I refresh that, any time it display me first route (Home in this example) but url point to outher route. What is wrong?


Viewing all articles
Browse latest Browse all 142382

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>