刷新浏览器时,react-router不起作用

时间:2018-09-02 20:56:57

标签: reactjs webpack react-router

我将react-router与webpack一起使用,当我单击该链接可正常工作时,但刷新页面时,收到此消息“ Cannot GET / sas”

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>


import React, { Component } from 'react'
import { BrowserRouter as Router, Route, NavLink } from 'react-router-dom'

import { HashLink } from 'react-router-hash-link'

import Homepage from '../homepage/homepage'
import Sas from '../sas/sas'

const Routes = () => {
    return (
<Router>
    <div>
        <nav className="navbar fixed-top navbar-expand-sm navbar-light bg-white py-3">
	        <NavLink className="navbar-brand right-border-menu px-5" exact to="/">Statuts Juridiques</NavLink>
	        <button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
	            <span className="navbar-toggler-icon"></span>
		</button>
		<div className="collapse navbar-collapse flex-row-reverse" id="navbarNavAltMarkup">
		    <div className="navbar-nav">
	            <NavLink className="nav-item nav-link" exact to="/sas">Je crée mon entreprise</NavLink>
			</div>
	</div>
</nav>

<Route path='/' exact strict component={Homepage} />
<Route path='/sas' exact strict component={Sas} />

   </div>
 </Router>
    )
}

export default Routes

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

import React, { Component } from 'react'

class Sas extends Component {
		
  render() {
return(
  <div className="column justify-content-center align-item-center my-5 py-5">
			
	  Sas page
				
  </div>
)
  }
}
	
export default Sas

0 个答案:

没有答案