
DINHDANH Creator · Bài EM06 · Easy · 3 method route
add · remove · get - đủ cấu trúc
Chỉ index.html chạy sẵn. Easy: route = client đọc/ghi routes.json (không phải action máy chủ riêng như Aura).
addRoute + file HTML handler. Xóa nội dung → removeRoute.appifio_addRoute(routeKey, filePath, type?)Việc: Map phần URL sau tên link → file trang.
Tham số:
routeKey- vd.bai-viet-ve-aihoặc lồngtag/javascriptfilePath- vd.blog/detail.htmltype- tuỳ chọn, vd.'blog','tag'(mặc định null)
const r = await appifio_client.appifio_addRoute(
'bai-viet-ve-ai',
'blog/detail.html',
'blog'
);
await appifio_client.appifio_addRoute('tag/javascript', 'blog/tag.html', 'tag');Trả về: { success, message? }. Bên trong: đọc routes.json → sửa → ghi lại. Aura: API route + thường cần admin.
appifio_removeRoute(routeKey)await appifio_client.appifio_removeRoute('bai-viet-ve-ai');Trả về: { success }. Bỏ dòng trong routes.json. URL đó sẽ 404 nếu không còn map.
appifio_getRoutes()Việc: Đọc toàn bộ map (JS đã parse giúp).
const r = await appifio_client.appifio_getRoutes();
if (r.success) {
const routes = r.data.routes || {};
const fallback = r.data.fallback; // thường "index.html"
}Trả về: { data: { routes: { [key]: { file, type?, enabled? } }, fallback? } } - không cần JSON.parse thêm.
URL tuyệt đối (thẻ base)
Không phải method Storage - helper bạn tự gắn trên trang (tránh link tương đối lệch vì
function getAbsoluteUrl(path) {
let siteUrl = window.location.origin;
const apps = window.appifio?.global?.apps;
if (apps?.site_url) siteUrl = apps.site_url.replace(/\/$/, '');
let urlName = apps?.url_name
|| window.location.pathname.split('/').filter(Boolean)[0]
|| '';
return siteUrl + '/' + urlName + '/' + String(path).replace(/^\//, '');
}EM07 - Helper (đủ method)
Điều hướng nội bộ (cùng ngôn ngữ)
DINHDANH Creator · Loạt Easy Storage · EM06