主要
分支
主要 (6.23.1)開發
版本
6.23.1v4/5.xv3.x
參與
本頁涵蓋

貢獻 React Router

感謝您的貢獻,您太讚了!

提到開源,有許多不同類型的貢獻方式,所有貢獻都非常寶貴。以下提供一些指南,應有助於您準備貢獻。

設定

在您能開始貢獻程式碼之前,您需要 fork 儲存庫。這會有些許不同,視您所作貢獻的類型而定

  • 所有新增功能、錯誤修正,或任何會變更 react-router 程式碼的內容都應從 dev 分支分岔,並合併到其中
  • 如果變更只會影響文件,則可從 main 分支分岔,並合併到其中

以下步驟將幫助您設定,以便開始對這個儲存庫進行變更

  1. fork 儲存庫(按一下 此頁面右上方的 [fork] 按鈕)
  2. 在本機複製您的 fork
# in a terminal, cd to parent directory where you want your clone to be, then
git clone https://github.com/<your_github_username>/react-router.git
cd react-router

# if you are making *any* code changes, make sure to checkout the dev branch
git checkout dev
  1. 安裝相依性關係並進行建立。React Router 使用 pnpm,您也應如此。如果您使用 npm 安裝,將會產生不必要的 package-lock.json 檔案。

認為你找到了錯誤?

請符合錯誤範本並提供清晰的重現途徑和程式碼範例。最好是提交一個含有失敗測試的 Pull Request,其次是提供連結至 CodeSandbox 或展示錯誤的存放庫。

要新增範例嗎?

範例可以直接新增到主分支。從你本地的主分支建立一個新分支,完成後,建立一個 Pull Request 並說明範例內容。

想建議新 API 或變更 API 嗎?

請提供周詳的說明和範例程式碼,展示你想用 React Router 在應用程式中執行的動作。如果你能先在開始猜測需要變更和/或新增什麼之前,展示你受限於目前 API 的地方,將有助於討論。

我們從經驗中得知,較小的 API 通常比較好,因此除非目前 API 有明顯的限制,否則我們可能不太願意新增新東西。話雖如此,我們總是 eager 聽到我們以前沒想過的情況,所以請不要害羞! :)

問題沒有獲得關注嗎?

如果你需要修復錯誤,而且沒有人要修復,你能做的最好做法是提供修復方法並建立一個 Pull Request。開放原始碼屬於我們所有人,而推動它向前也是我們所有人的責任。

要建立一個 Pull Request 嗎?

Pull Request 只要獲得兩個或更多協作者批准就能合併,如果 PR 作者是協作者,則算一個。

在 GitHub 中建立 PR 時,請確保你將基礎設定為正確的分支。如果你提交影響任何程式碼的 PR,這個分支應該是 dev 分支。你可以在 GitHub 中撰寫 PR 時,選擇「比較變更」標題下方的下拉式選單來設定基礎:

測試

修正錯誤或新增功能的所有提交都需要一個測試。

<blink>沒有測試,就不要合併程式碼!</blink>

文件 + 範例

變更或新增 API 的所有提交都必須在一個 Pull Request 中完成,這個 Pull Request 還要更新所有相關的範例和文件。

開發

套件

React Router 使用一個 mono repo 來 hosting 多個套件的程式碼,這些套件放在 packages 目錄中。

我們使用 pnpm 工作空間 來管理依賴項目的安裝,並執行各種腳本。要安裝所有項目,請務必已 安裝 pnpm,然後從倉庫根目錄執行 `pnpm install`。

建立

從根目錄呼叫 `pnpm build` 會執行建立,僅需要幾秒鐘。一起建立所有套件非常重要,因為 `react-router-dom` 和 `react-router-native` 都使用 `react-router` 做為依賴項。

測試

執行測試之前,您需要進行一次建立。在建立後,從根目錄執行 `pnpm test` 會執行 **每個** 套件的測試。如果您想執行特定套件的測試,請使用 `pnpm test --projects packages/<package-name>`

# Test all packages
pnpm test

# Test only react-router-dom
pnpm test --projects packages/react-router-dom

倉庫分歧

此倉庫維護不同目的的分歧。它們會類似於以下項目

- main   > the most recent release and current docs
- dev    > code under active development between stable releases
- v5     > the most recent code for a specific major release

可能會有其他分歧,用於各種功能和實驗,但所有神奇的事情都發生在這些分歧中。

新版本

該發行新版本時,我們依照我們的分歧策略,根據版本的類型遵循一個程序。

react-router@next 版本

我們根據 `dev` 分歧的目前狀態建立實驗性版本。它們可以使用 `@next` 標籤安裝

pnpm add react-router-dom@next
# or
npm install react-router-dom@next

這些版本會在公關合併到 `dev` 分歧時自動化。

最新主要版本

# Start from the dev branch.
git checkout dev

# Merge the main branch into dev to ensure that any hotfixes and
# docs updates are available in the release.
git merge main

# Create a new release branch from dev.
git checkout -b release/v6.1.0

# Create a new tag and update version references throughout the
# codebase.
pnpm run version minor # | "patch" | "major"

# Push the release branch along with the new release tag.
git push origin release/v6.1.0 --follow-tags

# Wait for GitHub actions to run all tests. If the tests pass, the
# release is ready to go! Merge the release branch into main and dev.
git checkout main
git merge release/v6.1.0
git checkout dev
git merge release/v6.1.0

# The release branch can now be deleted.
git branch -D release/v6.1.0
git push origin --delete release/v6.1.0

# Now go to GitHub and create the release from the new tag. Let
# GitHub Actions take care of the rest!

修正版本

有時我們會遇到必須立即修補的重要錯誤。如果錯誤影響最新版本,我們可以直接從 `main`(或存在錯誤的相關主要版本分歧)建立新的版本

# From the main branch, make sure to run the build and all tests
# before creating a new release.
pnpm install && pnpm build && pnpm test

# Assuming the tests pass, create the release tag and update
# version references throughout the codebase.
pnpm run version patch

# Push changes along with the new release tag.
git push origin main --follow-tags

# In GitHub, create the release from the new tag and it will be
# published via GitHub actions

# When the hot-fix is done, merge the changes into dev and clean
# up conflicts as needed.
git checkout dev
git merge main
git push origin dev