react-router4@笔记


新项目使用react-router@4来进行路由跳转,使用非static的配置方式该用jsx。之前配置动态生成路由一直报错,发现提示route必须要有父级,在外面嵌套了div,才成功了,但是在官方文档中并未提及,也没看懂他的用意。


0、 页面入口

import React,{Component} from "react";
import reactDom from 'react-dom';
import "../css/index.less";
import SNCRouter from "./route"

class Index extends Component{
    componentWillReceiveProps(){

    }
   componentDidMount(){
      console.log("index")
   }
   render(){
       return 
} } reactDom.render(,document.querySelector("#SNC-router"))

1、路由代码

import React, { Component } from "react";
import { HashRouter as Router, Route, Link, Switch } from 'react-router-dom';
import { send, store } from "../controller/reduxList.js";
import { routerIndex } from '../route/route-index';
const routers = [...routerIndex];
class SNCRouter extends Component {
    set404() {
        return 
404
} setRoute() { return routers.map((r, i) => { return }) } render() { return { this.setRoute() } } } export default SNCRouter;

你可能感兴趣的:(react-router4@笔记)