ディープリンクとプロトコルハンドラー
カスタムURLスキームからElectronアプリを起動して移動できるようにします。起動イベントや更新機能を補完する、重要なライフサイクル連携です。
「ディープリンクとプロトコルハンドラー」はCoddyKit上の無料Electron Desktop App Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはElectron Desktop App Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Electron Desktop App Developmentコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Launching From a Link
Deep linking lets a URL like myapp://open/project/42 launch or focus your app and jump straight to content.
Custom Protocols
Register a custom URL scheme so the OS knows links of that type belong to your app.
app.setAsDefaultProtocolClient('myapp');Parsing the Deep Link
Extract the path and parameters from the incoming URL to decide where to navigate.
function parseDeepLink(url) {
const u = new URL(url);
return { host: u.host, path: u.pathname };
}
console.log(parseDeepLink('myapp://open/project/42'));Handling Links on macOS
On macOS, deep links arrive via the open-url event, even while the app is running.
app.on('open-url', (event, url) => {
event.preventDefault();
handleLink(url);
});Handling Links on Windows and Linux
On Windows and Linux the URL comes in as a command-line argument, so inspect process.argv on launch.
function urlFromArgv(argv) {
return argv.find(a => a.startsWith('myapp://'));
}
console.log(urlFromArgv(['electron', '.', 'myapp://open/5']));Single Instance Coordination
Use the single instance lock so a second launch forwards its URL to the already-running app instead of starting a new one.
const gotLock = app.requestSingleInstanceLock();
if (!gotLock) app.quit();second-instance Event
The second-instance event delivers the new command line, where the deep link lives, and lets you focus the main window.
app.on('second-instance', (e, argv) => {
const url = urlFromArgv(argv);
if (url) handleLink(url);
});Cold Start vs Warm Start
Handle both cases: the app launched fresh by the link (cold) and the app already open (warm). Route both to the same handler.
Validating the Link
Never trust a deep link blindly. Validate the path and parameters before acting on them to avoid abuse.
Testing Deep Links
Test by typing the URL into a browser or terminal. During development the scheme must point at your packaged or running app.
Use Cases
Deep links power OAuth callbacks, sharing, and notifications that jump straight to relevant content, tying nicely into the app lifecycle.
Quick Check
Test your deep linking knowledge.
Recap
You learned to register a custom protocol, parse deep links, handle them across platforms, coordinate with the single-instance lock, and validate input, enabling URL-driven app navigation.
よくある質問
「ディープリンクとプロトコルハンドラー」レッスンは無料ですか?
はい。「ディープリンクとプロトコルハンドラー」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Electron Desktop App Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Electron Desktop App Developmentコースには全4レッスンが含まれています。
「ディープリンクとプロトコルハンドラー」で何を学びますか?
カスタムURLスキームからElectronアプリを起動して移動できるようにします。起動イベントや更新機能を補完する、重要なライフサイクル連携です。 ブラウザで直接実行するハンズオンコードでElectron Desktop App Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Electron Desktop App Developmentを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのElectron Desktop App Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「ディープリンクとプロトコルハンドラー」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このElectron Desktop App Developmentレッスンでコードを書いて実行できますか?
はい。すべてのElectron Desktop App Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- アプリケーションのライフサイクルイベント管理
- 自動更新の実装
- クラッシュレポート
- ディープリンクとプロトコルハンドラー