Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说npm切换淘宝镜像「建议收藏」,希望能够帮助你!!!。
1.npm i nrm -g
2.nrm Ls
3.nrm use taobao
下面是安装yarn命令
npm i yarn -g
重新现在依赖包 npm i
解包 npm run eject
卸载某个包 用 npm uni
react项目运行命令为 yarn start
vue项目运行命令为 yarn serve
npm install axios
如果下载特定版本需要在后面加@版本号
还需要下载路由react-router-dom
npm install react-router-dom --save
import Page1 from './pages/Page1'
import Page2 from './pages/Page2'
import React, { Component } from 'react'
import { Route, Switch, withRouter, BrowserRouter } from 'react-router-dom'
class Router extends Component {
constructor(props) {
super(props)
this.state = {
}
}
render() {
return (
<BrowserRouter>
<Switch>
<Route exact path="/" component={withRouter(Page1)} />
<Route exact path="/page2" component={withRouter(Page2)} />
</Switch>
</BrowserRouter>
)
}
}
export default Router
三、修改index.js文件
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
// import App from './App';
import Router from './Router'
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<Router />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
下边的那种写法都可以,前两种传参的话会暴露在地址栏,第三种比较优雅,不会暴露在地址栏,但是浏览器刷新后参数就没了,需要配合存储使用。
this.props.history.push('/page2')
this.props.history.push({pathname:'/page2'})
this.props.history.push({pathname:"/page2",state : { id : '111' }});
五、路由传参
this.props.history.push('/page2/' + 666 + '')
this.props.history.push({pathname:'/'})
上边的写法传参就是要在后边拼接
不推荐用上边的写法传参,改变URL,可能导致路由失败
this.props.history.push({pathname:"/page2",state : { id : '111' }});
获取数据:this.props.location.state.id
上一篇
已是最后文章
下一篇
已是最新文章