Replace querystring routes with conventional routes
This commit is contained in:
@ -26,18 +26,18 @@
|
|||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
[CascadingParameter] PageState PageState { get; set; }
|
[CascadingParameter] PageState PageState { get; set; }
|
||||||
|
|
||||||
[Parameter] Action<PageState> OnStateChange { get; set; }
|
[Parameter] Action<PageState> OnStateChange { get; set; }
|
||||||
|
|
||||||
PageState pagestate;
|
PageState pagestate;
|
||||||
RenderFragment DynamicComponent { get; set; }
|
RenderFragment DynamicComponent { get; set; }
|
||||||
|
|
||||||
string _absoluteUri;
|
string _absoluteUri;
|
||||||
bool _navigationInterceptionEnabled;
|
bool _navigationInterceptionEnabled;
|
||||||
|
|
||||||
protected override void OnInit()
|
protected override void OnInit()
|
||||||
{
|
{
|
||||||
_absoluteUri = UriHelper.GetAbsoluteUri();
|
_absoluteUri = UriHelper.GetAbsoluteUri();
|
||||||
UriHelper.OnLocationChanged += OnLocationChanged;
|
UriHelper.OnLocationChanged += OnLocationChanged;
|
||||||
|
|
||||||
@ -49,23 +49,23 @@ protected override void OnInit()
|
|||||||
builder.CloseComponent();
|
builder.CloseComponent();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
UriHelper.OnLocationChanged -= OnLocationChanged;
|
UriHelper.OnLocationChanged -= OnLocationChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
if (PageState == null)
|
if (PageState == null)
|
||||||
{
|
{
|
||||||
await Refresh();
|
await Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Refresh()
|
private async Task Refresh()
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> moduledefinitions;
|
List<ModuleDefinition> moduledefinitions;
|
||||||
List<Models.Theme> themes;
|
List<Models.Theme> themes;
|
||||||
List<Alias> aliases;
|
List<Alias> aliases;
|
||||||
@ -75,6 +75,8 @@ private async Task Refresh()
|
|||||||
Page page;
|
Page page;
|
||||||
User user;
|
User user;
|
||||||
List<Module> modules;
|
List<Module> modules;
|
||||||
|
int moduleid = -1;
|
||||||
|
string control = "";
|
||||||
|
|
||||||
bool reload = false;
|
bool reload = false;
|
||||||
if (PageState == null)
|
if (PageState == null)
|
||||||
@ -144,10 +146,30 @@ private async Task Refresh()
|
|||||||
pages = PageState.Pages;
|
pages = PageState.Pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// format path so that it can be located in the pages collection
|
||||||
if (path.IndexOf("?") != -1)
|
if (path.IndexOf("?") != -1)
|
||||||
{
|
{
|
||||||
|
// remove querystring from path
|
||||||
path = path.Substring(0, path.IndexOf("?"));
|
path = path.Substring(0, path.IndexOf("?"));
|
||||||
}
|
}
|
||||||
|
// remove admin route elements from path
|
||||||
|
string[] segments = path.Split('/');
|
||||||
|
int result;
|
||||||
|
// admin routes are in the form of path/moduleid/control or path/moduleid
|
||||||
|
if (segments.Length >= 2 && int.TryParse(segments[segments.Length - 2], out result))
|
||||||
|
{
|
||||||
|
control = segments[segments.Length - 1];
|
||||||
|
moduleid = result;
|
||||||
|
path = path.Replace("/" + moduleid.ToString() + "/" + control, "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (segments.Length >= 1 && int.TryParse(segments[segments.Length - 1], out result))
|
||||||
|
{
|
||||||
|
moduleid = result;
|
||||||
|
path = path.Replace("/" + moduleid.ToString(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (PageState == null || reload == true)
|
if (PageState == null || reload == true)
|
||||||
{
|
{
|
||||||
@ -179,17 +201,9 @@ private async Task Refresh()
|
|||||||
pagestate.User = user;
|
pagestate.User = user;
|
||||||
pagestate.Uri = new Uri(_absoluteUri, UriKind.Absolute);
|
pagestate.Uri = new Uri(_absoluteUri, UriKind.Absolute);
|
||||||
pagestate.QueryString = querystring;
|
pagestate.QueryString = querystring;
|
||||||
pagestate.ModuleId = -1;
|
pagestate.ModuleId = moduleid;
|
||||||
pagestate.Control = "";
|
pagestate.Control = control;
|
||||||
|
|
||||||
if (querystring.ContainsKey("mid"))
|
|
||||||
{
|
|
||||||
pagestate.ModuleId = int.Parse(querystring["mid"]);
|
|
||||||
}
|
|
||||||
if (querystring.ContainsKey("ctl"))
|
|
||||||
{
|
|
||||||
pagestate.Control = querystring["ctl"];
|
|
||||||
}
|
|
||||||
if (PageState != null && (PageState.ModuleId != pagestate.ModuleId || PageState.Control != pagestate.Control))
|
if (PageState != null && (PageState.ModuleId != pagestate.ModuleId || PageState.Control != pagestate.Control))
|
||||||
{
|
{
|
||||||
reload = true;
|
reload = true;
|
||||||
@ -222,26 +236,26 @@ private async Task Refresh()
|
|||||||
{
|
{
|
||||||
// site does not exist
|
// site does not exist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnLocationChanged(object sender, LocationChangedEventArgs args)
|
private async void OnLocationChanged(object sender, LocationChangedEventArgs args)
|
||||||
{
|
{
|
||||||
_absoluteUri = args.Location;
|
_absoluteUri = args.Location;
|
||||||
await Refresh();
|
await Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
Task IHandleAfterRender.OnAfterRenderAsync()
|
Task IHandleAfterRender.OnAfterRenderAsync()
|
||||||
{
|
{
|
||||||
if (!_navigationInterceptionEnabled && ComponentContext.IsConnected)
|
if (!_navigationInterceptionEnabled && ComponentContext.IsConnected)
|
||||||
{
|
{
|
||||||
_navigationInterceptionEnabled = true;
|
_navigationInterceptionEnabled = true;
|
||||||
return NavigationInterception.EnableNavigationInterceptionAsync();
|
return NavigationInterception.EnableNavigationInterceptionAsync();
|
||||||
}
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, string> ParseQueryString(string path)
|
private Dictionary<string, string> ParseQueryString(string path)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> querystring = new Dictionary<string, string>();
|
Dictionary<string, string> querystring = new Dictionary<string, string>();
|
||||||
if (path.IndexOf("?") != -1)
|
if (path.IndexOf("?") != -1)
|
||||||
{
|
{
|
||||||
@ -262,10 +276,10 @@ private Dictionary<string, string> ParseQueryString(string path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return querystring;
|
return querystring;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Module> ProcessModules(List<Module> modules, List<ModuleDefinition> moduledefinitions, string control, string panes)
|
private List<Module> ProcessModules(List<Module> modules, List<ModuleDefinition> moduledefinitions, string control, string panes)
|
||||||
{
|
{
|
||||||
ModuleDefinition moduledefinition;
|
ModuleDefinition moduledefinition;
|
||||||
|
|
||||||
if (control == "")
|
if (control == "")
|
||||||
@ -317,10 +331,10 @@ private List<Module> ProcessModules(List<Module> modules, List<ModuleDefinition>
|
|||||||
module.PaneModuleCount = paneindex[module.Pane] + 1;
|
module.PaneModuleCount = paneindex[module.Pane] + 1;
|
||||||
}
|
}
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Alias GetAlias(string absoluteUri, List<Alias> aliases)
|
private Alias GetAlias(string absoluteUri, List<Alias> aliases)
|
||||||
{
|
{
|
||||||
|
|
||||||
string aliasname;
|
string aliasname;
|
||||||
Alias alias = null;
|
Alias alias = null;
|
||||||
@ -345,6 +359,6 @@ private Alias GetAlias(string absoluteUri, List<Alias> aliases)
|
|||||||
}
|
}
|
||||||
alias.Scheme = uri.Scheme;
|
alias.Scheme = uri.Scheme;
|
||||||
return alias;
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -44,14 +44,19 @@ namespace Oqtane.Shared
|
|||||||
|
|
||||||
public static string EditUrl(PageState pagestate, Module modulestate, string action, string parameters)
|
public static string EditUrl(PageState pagestate, Module modulestate, string action, string parameters)
|
||||||
{
|
{
|
||||||
string url = pagestate.Alias.Path + "/" + pagestate.Page.Path + "?mid=" + modulestate.ModuleId.ToString();
|
string url = pagestate.Alias.Path;
|
||||||
|
if (pagestate.Page.Path != "")
|
||||||
|
{
|
||||||
|
url += "/" + pagestate.Page.Path;
|
||||||
|
}
|
||||||
|
url += "/" + modulestate.ModuleId.ToString();
|
||||||
if (action != "")
|
if (action != "")
|
||||||
{
|
{
|
||||||
url += "&ctl=" + action;
|
url += "/" + action;
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(parameters))
|
if (!string.IsNullOrEmpty(parameters))
|
||||||
{
|
{
|
||||||
url += "&" + parameters;
|
url += "?" + parameters;
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user