正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

URLs in GitLab

一貫した開発プロセスとドキュメントを確保するため、GitLabへのすべての貢献は英語で提出する必要があります。そのため、GitLabへの貢献に関するドキュメント(https://docs.gitlab.com/development/に掲載)も英語でのみ提供されています。

以下を希望される場合:

  • コードの貢献を提出する
  • バグの報告または修正
  • 機能や改善の提案
  • ドキュメントへの貢献

これらのページの英語版のガイドラインに従ってください。

このページの英語版にアクセスしてください。

Overview

GitLab supports multiple deployment configurations that affect how URLs are generated and resolved. Using hardcoded or absolute URLs can break functionality in these scenarios:

To ensure URLs work correctly across all deployment configurations follow the below guidelines.

General guidelines

  • Use Rails as the single source of truth for generating URLs. If you need a URL on the frontend, generate it in Rails and pass it to the frontend.
  • Use relative URLs for internal application links. Use absolute URLs only when:
    • Generating links for emails.
    • Constructing URLs for external services.
    • Building clone or download URLs that must work outside the web interface.

Backend guidelines

Path and URL helpers

Use Rails path and URL helpers to generate URLs.

  • Use *_path helpers for all internal application links.
  • Use *_url helpers only for links that need to be consumed outside of the application, such as:
    • Links for emails.
    • URLs for external services.
    • Clone or download URLs that must work outside the web interface.
# Correct - Relative path
redirect_to project_path(@project)

# Incorrect - Absolute URL
redirect_to project_url(@project)

Frontend guidelines

JavaScript and Vue

Do not hardcode or construct URLs in JavaScript or Vue. Generate URLs in Rails and pass them to the frontend through data attributes, GraphQL queries, or REST APIs.

// Incorrect - Do not construct URLs on the frontend
const endpoint = `${gon.relative_url_root}/${projectPath}/-/refs`;

For correct alternatives, see the following sections.

Passing URLs with data attributes

Pass URLs from Rails to the frontend by using data-* attributes. For example:

#js-my-app{ data: { base_path: project_iteration_cadences_path(project) } }
const initMyApp = () => {
  const el = document.getElementById('js-my-app');

  if (!el) return false;

  const { basePath } = el.dataset
}

GraphQL queries

Avoid using webUrl fields. Instead, use the webPath or other relative URL field, for example, adminEditPath. If the webPath field does not exist on that GraphQL type, add it. Be careful of compatibility across updates when you add new GraphQL fields.

REST API

Avoid using web_url fields. Instead, use web_path or other relative URL fields, for example, admin_edit_path. If web_path does not exist on the REST API endpoint, add it. Be careful of compatibility across updates when you add new fields to REST API endpoints.

Vue router

For the correct way to configure Vue Router, see Vue Router.

HAML templates

Use *_path helpers instead of *_url helpers:

-# Correct - Relative URL
= link_to _('Dashboard'), dashboard_projects_path

-# Incorrect - Absolute URL
= link_to _('Dashboard'), dashboard_projects_url