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

实现效果:

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值