javascript React-router启动码#react

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript React-router启动码#react相关的知识,希望对你有一定的参考价值。

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import { BrowserRouter, Route, Switch } from "react-router-dom";
import promise from 'redux-promise';

import PostsIndex from './components/posts_index';
import PostsNew from './components/posts_new';
import reducers from './reducers';
import PostsShow from './components/posts_show';

const createStoreWithMiddleware = applyMiddleware(promise)(createStore);

//note: path with unique routes should start at the top since React router parses routes in wildcard state.
ReactDOM.render(
  <Provider store={createStoreWithMiddleware(reducers)}>
    <BrowserRouter>
    	<div>
    		<Switch>
		    	<Route path="/posts/new" component={ PostsNew } /> 
				<Route path="/posts/:id" component={ PostsShow } />
		    	<Route path="/" component={ PostsIndex } />
	    	</Switch>
    	</div>
    </BrowserRouter>
  </Provider>
  , document.querySelector('.container'));

以上是关于javascript React-router启动码#react的主要内容,如果未能解决你的问题,请参考以下文章

2021 react-router v6 快速入门

react-router browserHistory刷新页面404问题解决方法

脚手架初始化 react 项目 react-router 路由

[转] react-router4 实现按需加载

react-router的使用——路由的嵌套

使用 Passport + Facebook + Express + create-react-app + React-Router + 代理进行身份验证