Umijs带底部导航路由切换动画

简介: Umijs带底部导航路由切换动画

实现效果:

image.png

umi实现路由动画

文件目录结构:

.umirc.ts文件配置:

routes: [
    {
      path: '/login',
      component: '@/pages/login/login.tsx',
    },
    {
    path: '/',
    component: '@/pages/home/home.tsx',
    exact: false,
    wrappers: ['@/wrappers/auth'],
    routes: [
      {
        path: '/',
        component: '@/pages/home/home/home',
        wrappers: ['@/wrappers/auth'],
      },
      {
        path: '/type',
        component: '@/pages/home/type/type',
        wrappers: ['@/wrappers/auth'],
      },
      {
        path: '/shopping',
        component: '@/pages/home/shop/shop',
        wrappers: ['@/wrappers/auth'],
      },
    ],
  },
],

home.tsx文件配置:

import React from 'react';
import { NavBar, TabBar } from 'antd-mobile';
import './home.less';
import {
  useHistory,
  useLocation,
  MemoryRouter as Router,
  Switch
} from 'react-router-dom';
import {
  AppOutline,
  UnorderedListOutline,
  UserOutline,
  FileOutline,
} from 'antd-mobile-icons';
import { TransitionGroup, CSSTransition } from 'react-transition-group'
export default (props: any) => {
  const tabs = [
    {
      key: '/',
      title: '首页',
      icon: <AppOutline />,
    },
    {
      key: '/type',
      title: '分类',
      icon: <UnorderedListOutline />,
    },
    {
      key: '/shopping',
      title: '购物车',
      icon: <FileOutline />,
    },
    {
      key: '/person',
      title: '个人',
      icon: <UserOutline />,
    },
  ];
  const history = useHistory();
  const location = useLocation();
  const { pathname } = location;
  const setRouteActive = (value: string) => {
    history.push(value);
  };
  const routerType = {
    'POP': 'back',
    'PUSH': 'dg',
    'REPLACE': 'dg'
  }
  return (
    <div className="app">
      <div className="body">
        <TransitionGroup className='transition_wrapper' style={{ width: '100%', height: '100%' }} childFactory={(child) => (
          React.cloneElement(child, { classNames: routerType[history.action] })
        )}>
          <CSSTransition key={props.location.pathname} appear timeout={1000}>
            {props.children}
          </CSSTransition>
        </TransitionGroup>
      </div>
      <div className="bottom">
        <TabBar activeKey={pathname} onChange={(value: any) => setRouteActive(value)}>
          {tabs.map((item) => (
            <TabBar.Item key={item.key} icon={item.icon} title={item.title} />
          ))}
        </TabBar>
      </div>
    </div>
  );
};

home.less文件配置:

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.top {
  flex: 0;
  border-bottom: solid 1px var(--adm-color-border);
}
body{
  margin: 0;
}
.body {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}
.bottom {
  flex: 0;
  border-top: solid 1px var(--adm-color-border);
  background-color: #fff !important;
  z-index: 200;
  position: fixed;
  width: 100vw;
  bottom: 0;
}
.dg-enter {
  transform: translate(100%, 0);
}
.dg-enter-active {
  transition: 3s;
  transform: translate(0);
}
.dg-enter-done {
  transform: translate(0);
}
.dg-exit-active {
  transition: 1s;
  transform: translate(-100%, 0);
}
.back-enter-active {
  transition: all 3s;
  transform: translate(0, 0) !important;
}
.back-enter-done {
  transform: translate(0, 0) !important;
}
.back-enter {
  z-index: 5 !important;
  transform: translate(-100%, 0);
}
.back-exit-active {
  opacity: 0;
  transition: all 3s;
  transform: translate(100%, 0) !important;
}


相关文章
|
Ubuntu 数据安全/隐私保护 Windows
Vagrant快速搭建Ubuntu虚拟机环境
Vagrant快速搭建Ubuntu虚拟机环境
1106 0
Vagrant快速搭建Ubuntu虚拟机环境
|
5月前
|
安全 搜索推荐 iOS开发
WPS Office for Mac 7.3.1 - 写作、表格处理、PPT 制作和 PDF 编辑
WPS Office for Mac 7.3.1 - 写作、表格处理、PPT 制作和 PDF 编辑
262 8
WPS Office for Mac 7.3.1 - 写作、表格处理、PPT 制作和 PDF 编辑
|
11月前
|
UED
|
缓存 前端开发 JavaScript
浅浅阅读umi中InitialState插件源码 - 杨磊
InitialState插件源码的简要介绍
1214 0
浅浅阅读umi中InitialState插件源码 - 杨磊
|
存储 安全 Cloud Native
如何在银行核心系统中安全地搭建微服务架构?
微服务作为现代互联网应用的主流架构风格,已在很多行业应用中获得广泛的成功,而银行核心系统由于其复杂性和风险敏感性,主流架构依然在从单体式 SOA 到真正的微服务分布式架构的转型期。
540 1
umi如何实现路由的动画跳转?
在src下新建一个layouts的文件夹,在layouts文件夹下新建两个文件
235 0
umi如何实现路由的动画跳转?
|
编解码 JavaScript 数据可视化
【vue3】 vue3 几款值得推荐的UI组件库
【vue3】 vue3 几款值得推荐的UI组件库
734 0
|
SQL 消息中间件 关系型数据库
基于 Flink CDC 的实时同步系统
科杰科技大数据架构师张军,在 FFA 数据集成专场的分享。
基于 Flink CDC 的实时同步系统
|
机器学习/深度学习 数据采集 人工智能
【时序预测】之水质净化厂工艺控制-曝气量预测(上)
【时序预测】之水质净化厂工艺控制-曝气量预测(上)
396 1
【时序预测】之水质净化厂工艺控制-曝气量预测(上)