fix: загрузка Telegram Login Widget через JS interop для корректной работы с Blazor SPA-навигацией
Deploy Telegram Bot / build-and-push (push) Successful in 3m17s
Deploy Telegram Bot / deploy (push) Successful in 9s

This commit is contained in:
2026-04-21 15:31:12 +03:00
parent 176f1105ab
commit 3002db6534
2 changed files with 25 additions and 7 deletions
+15
View File
@@ -22,6 +22,21 @@
<Routes @rendermode="InteractiveServer" />
<ReconnectModal />
<script src="@Assets["_framework/blazor.web.js"]"></script>
<script>
window.loadTelegramWidget = function (botUsername, authUrl) {
var container = document.getElementById('telegram-login-container');
if (!container) return;
container.innerHTML = '';
var script = document.createElement('script');
script.async = true;
script.src = 'https://telegram.org/js/telegram-widget.js?22';
script.setAttribute('data-telegram-login', botUsername);
script.setAttribute('data-size', 'large');
script.setAttribute('data-auth-url', authUrl);
script.setAttribute('data-request-access', 'write');
container.appendChild(script);
};
</script>
</body>
</html>
+10 -7
View File
@@ -2,6 +2,7 @@
@using Microsoft.AspNetCore.Components.Authorization
@inject NavigationManager Navigation
@inject IConfiguration Configuration
@inject IJSRuntime JS
<PageTitle>Вход — GM-Relay</PageTitle>
@@ -18,13 +19,7 @@
</div>
}
<div id="telegram-login-container">
<script async src="https://telegram.org/js/telegram-widget.js?22"
data-telegram-login="@BotUsername"
data-size="large"
data-auth-url="@AuthUrl"
data-request-access="write"></script>
</div>
<div id="telegram-login-container"></div>
</div>
</div>
@@ -46,4 +41,12 @@
}
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JS.InvokeVoidAsync("loadTelegramWidget", BotUsername, AuthUrl);
}
}
}