You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
import { Redirect } from 'expo-router';
|
|
import { StyleSheet, View } from 'react-native';
|
|
import { useAuth } from '../src/context/AuthContext';
|
|
import { useRole } from '../src/context/RoleContext';
|
|
import { colors } from '../src/theme';
|
|
|
|
/**
|
|
* 应用总入口(根路由 /)。
|
|
* 按「引导 → 登录 → 选择身份 → 对应端」漏斗放行,保证每个页面都有合理的前置入口。
|
|
*/
|
|
export default function Index() {
|
|
const { onboardingSeen, isTokenValid, isHydrated: authHydrated } = useAuth();
|
|
const { role, isHydrated: roleHydrated } = useRole();
|
|
|
|
// 本地存储读取完成前不做任何跳转决策,否则已登录用户会闪现引导页/注册页
|
|
if (!authHydrated || !roleHydrated) {
|
|
return <View style={styles.container} />;
|
|
}
|
|
|
|
if (!onboardingSeen) {
|
|
return <Redirect href="/guide" />;
|
|
}
|
|
if (!isTokenValid) {
|
|
return <Redirect href="/register" />;
|
|
}
|
|
if (!role) {
|
|
return <Redirect href="/register" />;
|
|
}
|
|
// 两个路由组均无 index,必须用显式落地路由,否则落地页空白
|
|
return (
|
|
<Redirect
|
|
href={role === 'candidate' ? '/(tabs)/jobs' : '/(enterprise)/job-management'}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: colors.white,
|
|
},
|
|
});
|
|
|