💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## React-Router相关问题 1. #### 如何使用JS代码,来动态控制路由的跳转? React-Router 返回的组件,属性里面有 history 变量,实现跳转的代码如下 `this.props.history.pushState(null, '/user' ) ` 2. #### React-Router二级路由,路由匹配返回的组件问题? 如果项目规模不是太小的话,就会存在一级模块,二级模块,亦或是三级模块。 如 `127.0.0.1:3000/#/user/detail` 这样的的路由,返回的detail组件,是挂在 一级模块 user 上的。 那么问题来了, 1. /user路由**有**相对应的组件 2. /user路由**没有**相对应的组件 **情况1:** `/user/detail` 返回的组件 ,在 **user 对应组件**的 `this.props.children` 属性中 **情况2:** `/user/detail` 返回的组件,在 **/ 对应的组件**的 `this.props.children` 属性中 ``` //情况1代码: module.exports = { path: 'user', //子路由 getChildRoutes(location, cb) { require.ensure([], (require) => { cb(null, [ require('./routes/test1') ]) }) }, //当前路由返回的控件 getComponent(location, cb) { require.ensure([], (require) => { console.log('user', location) cb(null, require('./components')) }) } } ``` ``` //情况2代码: module.exports = { path: 'authority', //子路由 getChildRoutes(location, cb) { require.ensure([], (require) => { cb(null, [ require('./authoritysp'), require('./datapolicy'), require('./list') ]) }) } } ```