Redirect From one app page to another SharePoint Hosted App
-
16-01-2021 - |
سؤال
Currenlt I am creating SharePoint hosted App. In which I have 2 pages Default .aspx and dashboard.aspx in Pages folder.
Now I want to redirect page from Default to dashboard.aspx.
One way I know is
window.location = window.location.href.replace('Default.aspx', 'Dashboard.aspx');
But sometimes Default.aspx might have '#' key word at last,hence doesnt work many times and also we dont know if some other key work might come in default.aspx's URL. Hence want to any URL string manipulation.
Please provide me some alternate solution in javascipt.
المحلول
This windows.location.hash
contains the anchor part of a URL. So
windows.location.assign(windows.location.href.replace(windows.location.hash,""));
نصائح أخرى
Use Relative Url to redirect to your custom pages Default Or Dashboard. This way you don't need to worry about URL hash #.
Simply use
window.location.href = "/sites/your-site/Pages/Dashboard.aspx"
This works 100% as it automatically calculates the domain and other params to form a web Url