import { objectToUrlParams } from "../utils/UrlParams.js";

export function navigateTo(url, args) {
  let targetUrl = url;
  if (args && typeof args === "object") {
    // 如果有额外参数，拼接到URL后面
    const paramString = objectToUrlParams(args);
    if (paramString) {
      if (targetUrl.contains("?")) {
        targetUrl += "&";
      } else {
        targetUrl += "?";
      }
      targetUrl += paramString;
    }
  }
  uni.navigateTo({
    url: "/pages/webview/index?url=" + encodeURIComponent(targetUrl),
  });
}
