jeecgboot/JeecgBoot · error · Error
token不存在~
Error message
token不存在~
What it means
Setup guard in the URL-style online Detail form — identical contract to the Add form's token guard. Throws if `token` is still falsy after `useFormUrl()` resolves, halting render because detail-data API calls need a bearer token.
Source
Thrown at jeecgboot-vue3/src/views/super/online/cgform/auto/default/OnlineFormUrlDetail.vue:44
// OnlineForm 这个必须引用,setup模式必须在template里面使用。否则url进入会报错
import OnlineForm from '../comp/OnlineForm.vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { useRoute } from 'vue-router';
import OnlineDetailModal from './OnlineDetailModal.vue';
import { useOnlineTableContext } from '../../hooks/auto/useOnlineTableContext';
import { useListButton } from '../../hooks/auto/useListButton';
import { useEnhance } from '../../hooks/auto/useEnhance';
import { useFormUrl } from '../../hooks/auto/useFormUrl';
const route = useRoute();
const { ID, onlineTableContext, onlineExtConfigJson } = useOnlineTableContext();
const { createMessage: $message } = useMessage();
const wrapRef = ref(null);
const contentHeight = ref(400);
const loading = ref(true);
const { token } = useFormUrl();
if (!unref(token)) {
throw new Error('token不存在~');
}
if (!ID.value || !route.params.dataId) {
$message.warning('地址错误, 配置ID不存在!');
throw new Error('地址错误, 配置ID不存在!');
}
watch(
() => wrapRef.value,
(elem: HTMLElement) => {
// 获取页面实际高度
contentHeight.value = elem.offsetHeight;
}
);
// 处理增强
let { initCgEnhanceJs } = useEnhance(onlineTableContext);
// 处理列表button
const { registerDetailModal, openDetailModal } = useListButton(onlineTableContext, onlineExtConfigJson);
const getContainer = (node) => {
return document.querySelector(`.online-detail-${ID.value}`);View on GitHub (pinned to 96fb33f5ec)
Solutions
- Log in to the platform first, then reopen the detail form.
- Append a valid `?token=<jwt>` to the detail URL for external use.
- Ensure the login/SSO flow sets the token before the detail route mounts.
- For embedding, mint a long-lived form token server-side and pass it in the URL.
Example fix
// before
const { token } = useFormUrl();
if (!unref(token)) { throw new Error('token不存在~'); }
// after — redirect to login preserving the return path
if (!unref(token)) {
router.replace({ path: '/user/login', query: { redirect: route.fullPath } });
return;
} Defensive patterns
Strategy: validation
Validate before calling
// confirm token presence before relying on it
const { token } = useFormUrl();
if (!unref(token)) {
router.replace({ path: '/user/login', query: { redirect: route.fullPath } });
return;
} Type guard
const hasToken = (t: unknown): t is string => typeof t === 'string' && t.length > 0;
Prevention
- Include `?token=` on externally shared detail links.
- Ensure login/SSO sets userStore.getToken before detail routes mount.
- Guard url-detail routes for token presence.
- Avoid the demo-token fetch path in production.
When it happens
Trigger: Opening the detail URL without `?token=` while not logged in (empty `userStore.getToken`); the async token fetch in `useFormUrl` hasn't completed so the synchronous guard throws.
Common situations: Shared detail link without a token; session expired; incognito window; SSO redirect loop left the user store empty.
Related errors
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/b18cb81c7fb284dd.
Report an issue: GitHub.