Bảng Routes hiện URL tuyệt đối đầy đủ
URL route tuyệt đối

DINHDANH Creator · Bài EM06 · Easy · 3 method route

Đường dẫn URL
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).

Quy tắc vàng: Tạo nội dung có URL riêng → bắt buộc 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-ai hoặc lồng tag/javascript
  • filePath - vd. blog/detail.html
  • type - 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(/^\//, '');
}
Checklist EM06 (3/3): addRoute · removeRoute · getRoutes (+ pattern URL tuyệt đối)

EM07 - Helper (đủ method)

DINHDANH Creator · Loạt Easy Storage · EM06