Absolute URI won't work - prism

Visual Studio 2017, Latest Xamarin.Forms, Latest Prism.
No matter what I try, I can't get my absolute URI to work. I have my app launch from app.xaml to a login page. In the loginpageviewmodel, I do some checks to see if the user is authenticated and if so, then I want to navigate to the mainpage.
I can navigate to the mainpage when not using absolute uri and it works - but the back button goes back to the login page - not wanted.
Code:
if (user.isAuthenticated)
{
navigationService.NavigateAsync("/AppMasterDetailPage/NavigationPage/MainPage"));
}
I've added all the http:// and the myapp.com, etc. ... nothing I try works.
How do I change the uri so absolute will navigate to proper main page and disallow the back button to the login page?

You can check out the following sample project which uses a "Login Screen" and a Hamburger Menu.
I haven't tested an attempted Navigation from OnNavigatingTo, but I wouldn't expect that to work properly as the page hasn't actually been pushed to the stack yet. That said if you did your check to see if the user is authenticated in OnNavigatedTo you could perform the navigation without a problem. If you do not want your user to see the LoginPage then the best I could tell you would be to have a SplashScreen that you first navigate to, and then do your logic from there to decide whether to go to your LoginPage or MasterDetailPage

I have a solution ...
I have app.xaml navigate to the loginpage. In the OnNavigatedTo method, I check for user authentication. If authenticated, then I call
NavigatgeAsync("/masterpage/navpage/mainpage");
and this gets me to the proper mainpage of the app and the back button DOES NOT go back to the login page - it exits app like expected. So the "/masterpage..." is the absolute uri I was looking for.

Next time you should do this instead _navigationService.NavigateAsync( new Uri("http://www.xxxx.com/Index/Navigation/Home", UriKind.Absolute)); this is after you have authenticated and have injected the NavigationService.

Related

Navigating to a page causes the app to gets stuck in the current page and exits debug mode automatically

I am working on the Xamarin iOS application and navigating to the login page that is when my app gets stuck in the current page ie the page where i am navigating from.
The debug point don't come to Initialise component of Login page nor it gets logged in catch the app gets stuck for a while and exits debug mode without any errors or exception
This navigation is basic, other pages are being navigated only issue is with the login page.
Also please let me know what parts of code should i Share
Please let me know if there is any solution.
I made a new page and copied all the contents of Login page to the new page and it worked, the underlying issue was the Login Page was corrupted when transferring from Windows To Mac,
As per why i think it was corrupted, because the debug point at Initialize component and onAppearing didn't work at all

How do I get the Router navigate extra "replaceUrl" to work correctly?

I have a contact addition form that can be navigated to from multiple screens in our application.
Once the form is submitted, I then take the user to a screen to view the contact that was added.
When the user then makes use of the back button it should take them back to the screen that they originated from.
This might be the Android back button or one that calls the RouterExtensions back function.
I have made use of the navigate extra replaceUrl when navigating away from the form to the view page.
I have also tried using the skipLocationChange extra when navigating to the form but this creates more issues.
I have created a simple playground page flow that creates not quite the same issue but does throw an error that I don't know what to do with either:
https://play.nativescript.org/?template=play-ng&id=BfVcGZ&v=2
In our app, by making use of the replaceUrl extra, the back button does take the user to the correct page.
However, there is a brief moment where they see the form again. This isn't an ideal user experience.
In the linked Playground I do get an error:
Cannot reattach ActivatedRouteSnapshot created from a different route.
This seems to tell me that replaceUrl is indeed removing the page from the route table.
However, the page isn't destroyed yet and so the app is trying to show a page that it shouldn't.
replaceUrl is not yet supported by Page Router Outlet, there is an open feature request, you might want to register your vote on the feature and follow up there for further updates.

Xamarin Page Navigation (again)

We're starting on a Xamarin.Forms app, and there are going to be quite a few pages and the navigation between pages will be handled completely by the app - specifically there is no back button, which shouldn't be a problem since we are only planning on releasing for iOS.
The first page the user encounters is the Login page, once logged in they go to the Home page. To perform this transition I just call
LoginPage.Navigation.PushModalAsync(HomePage)
and that's fine.
Now if, on the Home page, they press the Logout button, I could call PopModalAsync(), the problem is that the Logout button exists on all the pages, so the user could have followed a path like this:
Login -> Home -> Create -> Format -> Print -> Logout
and I need to immediately jump to the Login screen.
So on the Home page, if the user presses the Logout button, I tried calling
ApplicationHomePage.Navigation.PushModalAsync(LoginPage);
but got an exception:
System.InvalidOperationException: Page must not already have a parent.
So just for fun I thought I'd try the easy solution:
LoginPage.Parent = null;
ApplicationHomePage.Navigation.PushModalAsync(LoginPage);
I'm never going to have a back button, and the iPad doesn't have one, so the contents of the navigation stacks aren't really important (right?)
Is this method of navigating "legal"? Is it going to cause me some problem I'm not seeing right now?
I think you can take a look to this
You should don't add your login page to a NavigationStack. Change MainPage property is a good solution...

Replace Xamarin forms page without pushasync

I've searched through numerous online posts and can't find a suitable answer for this scenario. It's a pretty common requirement. I have a Xamarin.Forms app with a login page and listing page. When the app is started, the login page is displayed. When they login successfully, I want to display the listing page and prevent them from backing up by clicking on the toolbar back button or the hardware back button.
Change the MainPage
when you start the app you should have
Application.Current.MainPage = new LoginPage();
after login, something like
Application.Current.MainPage = new MyFirstPageAfterLogin();

JSF and browser back

I have a very strict requirement to use POST to pass in request parameters to my application upon entry. Once entering the application (page1), entering form information and continuing to the next page (page2) via a commandButton, the expectation is that the data will be posted and later read from a session scoped manage bean. All works well except when using browser back on page2 to navigate back to page1.
I have tried adding a redirect tag on the navigation rule that navigates from page1 to page2 to no avail. I have also tried this implementation of the Post-Get-Redirect pattern (http://balusc.blogspot.com/2007/03/post-redirect-get-pattern.html). Am I missing something obvious here?
Abel, the scope of page1 is request.
The solution we came up with which is no means ideal is to disable browser caching on the previous page. What this means is that whenever you refresh the page using the browser refresh button or click the browser back button, the browser will indicate that the page is expired and prompt a warning asking whether you want to re-submit the request.
We do have a work around which is to provide navigation buttons within the webpage but the idea was to support browser back. This would be easy using GET parameters, but POST provides additional complexity which we have decided to mitigate by by providing our in-house navigation buttons.

Resources