React+Router多级导航切换路由

背景

我们需要开发一个管理平台,登陆、注册及网站首页等不需要加载用户信息的页面放置在系统外部,系统内部则是需要验证用户身份及其角色的页面。

文件结构

注:输出文件树及文件 tree ./src /F

│  index.html 页面文件入口
│  index.js js文件入口
│  style.scss
├─actions
│      api.js
│      base.js
├─containers
│  │  contentMain.jsx 填充layout中的content部分
│  │  layout.jsx 系统页面中的布局,包含菜单导航
│  │  noPage.jsx  页面走丢
│  │  personal.jsx 
│  │  style.scss
│  ├─account
│  │      new.jsx
│  │      table.jsx
│  ├─clients
│  │      new.jsx
│  │      table.jsx
│  ├─firms
│  │      new.jsx
│  │      table.jsx
│  ├─index
│  │      index.jsx
│  │      items.jsx
│  │      style.scss
│  ├─login
│  │      index.jsx
│  │      style.scss
│  └─resetpassword
│          index.jsx
│          style.scss
└─ xxxxx···

最外层路由

import React from 'react';
import {
   render} from 'react-dom';
import {
   Provider} from 'react-redux';
import {
    HashRouter as Router, Route, Switch } from 'react-router-dom';

const IndexPage = require('./containers/index/index').default;
const Layout = require('./containers/layout').default;
const Login = require('./containers/login').default;
const RestPassWord = require('./containers/resetpassword').default;
const NotFoundPage = require('./containers/noPage').default;


import configureStore from './store';
import './style.scss'
const store = configureStore();

render(
    <Provider store={
   store}>
      <Router>
          <Switch>
            <Route path="/main" component={
   Layout} /> //模糊匹配,只要路由中有/main就会加载Layout组件
            <Route exact path="/index" component={
   IndexPage} /> // 精确匹配
            <Route exact path="/login" component={
   Login} 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值