React route using the default one page Switch Redirect show to find the difference between the stop BrowserRouter and HashRouter

Introducing
Redirect one page to show the default
Switch route once found will not stop looking down the

App.js
    import {Link,Route,NavLink,Redirect,Switch} from "react-router-dom"

    <NavLink to="/chuli" activeClassName="demo">Chuli</NavLink>
    <NavLink to="/clock" activeClassName="demo">Clock</NavLink>

    <Switch>
    <Route path="/Chuli" component={Chuli}></Route>
    <Route path="/Clock" component={Clock}></Route>
    <Redirect to="/chuli"></Redirect> //默认展示chuli页面
    </Switch>


 BrowserRouter 这一种 兼容性不好  多次刷新的时候  css样似可能会丢失
 HashRouter     这一种兼容好  但是有锚点
 如何解决 BrowserRouter的缺点

使用连接的时候 加上  %PUBLIC_URL%
home.css  在public目录下
<link rel="stylesheet" href="%PUBLIC_URL%/home.css"> 可以解决


 <link rel="stylesheet" href="./home.css">  失败 
 在react中 ./ 和 /  区别不同  /表示从项目暴露的资源目录开始查找

Guess you like

Origin www.cnblogs.com/IwishIcould/p/12057458.html