-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(templates): resolve issues of universal link in MAUI client of Bo…
- Loading branch information
Showing
7 changed files
with
87 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 4 additions & 64 deletions
68
....Boilerplate/src/Client/Boilerplate.Client.Core/Extensions/NavigationManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,14 @@ | ||
using System.Web; | ||
|
||
namespace Microsoft.AspNetCore.Components; | ||
namespace Microsoft.AspNetCore.Components; | ||
|
||
public static partial class NavigationManagerExtensions | ||
{ | ||
public static string GetUriWithoutQueryParameter(this NavigationManager navigationManager, string key) | ||
{ | ||
var url = navigationManager.Uri; | ||
|
||
var uri = new Uri(url); | ||
|
||
// this gets all the query string key value pairs as a collection | ||
var newQueryString = HttpUtility.ParseQueryString(uri.Query); | ||
|
||
// this removes the key if exists | ||
newQueryString.Remove(key); | ||
|
||
// this gets the page path from root without QueryString | ||
string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); | ||
|
||
return newQueryString.Count > 0 | ||
? string.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString) | ||
: pagePathWithoutQueryString; | ||
} | ||
|
||
/// <summary> | ||
/// Reads culture from either route segment or query string. | ||
/// https://adminpanel.bitpaltform.dev/en-US/categories | ||
/// https://adminpanel.bitpaltform.dev/categories?culture=en-US | ||
/// </summary> | ||
public static string? GetCultureFromUri(this NavigationManager navigationManager) | ||
{ | ||
var uri = new Uri(navigationManager.Uri); | ||
|
||
var culture = HttpUtility.ParseQueryString(uri.Query)["culture"]; | ||
|
||
if (string.IsNullOrEmpty(culture) is false) | ||
return culture; | ||
|
||
foreach (var segment in uri.Segments.Take(2)) | ||
{ | ||
var segmentValue = segment.Trim('/'); | ||
if (CultureInfoManager.SupportedCultures.Any(sc => string.Equals(sc.Culture.Name, segmentValue, StringComparison.InvariantCultureIgnoreCase))) | ||
{ | ||
return segmentValue; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static string GetUriWithoutCulture(this NavigationManager navigationManager) | ||
{ | ||
var uri = navigationManager.GetUriWithoutQueryParameter("culture"); | ||
|
||
var culture = navigationManager.GetCultureFromUri(); | ||
|
||
if (string.IsNullOrEmpty(culture) is false) | ||
{ | ||
uri = uri | ||
.Replace($"{culture}/", string.Empty) | ||
.Replace(culture, string.Empty); | ||
} | ||
|
||
return uri; | ||
return new Uri(navigationManager.Uri).GetUrlWithoutQueryParameter(key); | ||
} | ||
|
||
public static string GetPath(this NavigationManager navigationManager) | ||
public static string GetUriPath(this NavigationManager navigationManager) | ||
{ | ||
var uriBuilder = new UriBuilder(navigationManager.GetUriWithoutCulture()) { Query = string.Empty, Fragment = string.Empty }; | ||
return uriBuilder.Path; | ||
return new Uri(navigationManager.Uri).GetPath(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Extensions/UriExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Web; | ||
|
||
namespace System; | ||
|
||
public static partial class UriExtensions | ||
{ | ||
public static string GetUrlWithoutQueryParameter(this Uri uri, string key) | ||
{ | ||
// this gets all the query string key value pairs as a collection | ||
var newQueryString = HttpUtility.ParseQueryString(uri.Query); | ||
|
||
// this removes the key if exists | ||
newQueryString.Remove(key); | ||
|
||
// this gets the page path from root without QueryString | ||
string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path); | ||
|
||
return newQueryString.Count > 0 | ||
? string.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString) | ||
: pagePathWithoutQueryString; | ||
} | ||
|
||
/// <summary> | ||
/// Reads culture from either route segment or query string. | ||
/// https://adminpanel.bitpaltform.dev/en-US/categories | ||
/// https://adminpanel.bitpaltform.dev/categories?culture=en-US | ||
/// </summary> | ||
public static string? GetCulture(this Uri uri) | ||
{ | ||
var culture = HttpUtility.ParseQueryString(uri.Query)["culture"]; | ||
|
||
if (string.IsNullOrEmpty(culture) is false) | ||
return culture; | ||
|
||
foreach (var segment in uri.Segments.Take(2)) | ||
{ | ||
var segmentValue = segment.Trim('/'); | ||
if (CultureInfoManager.SupportedCultures.Any(sc => string.Equals(sc.Culture.Name, segmentValue, StringComparison.InvariantCultureIgnoreCase))) | ||
{ | ||
return segmentValue; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static string GetUrlWithoutCulture(this Uri uri) | ||
{ | ||
uri = new Uri(uri.GetUrlWithoutQueryParameter("culture")); | ||
|
||
var culture = uri.GetCulture(); | ||
|
||
if (string.IsNullOrEmpty(culture) is false) | ||
{ | ||
uri = new Uri(uri.ToString() | ||
.Replace($"{culture}/", string.Empty) | ||
.Replace(culture, string.Empty)); | ||
} | ||
|
||
return uri.ToString(); | ||
} | ||
|
||
public static string GetPath(this Uri uri) | ||
{ | ||
var uriBuilder = new UriBuilder(uri.GetUrlWithoutCulture()) { Query = string.Empty, Fragment = string.Empty }; | ||
return uriBuilder.Path; | ||
} | ||
} |