How to perform Deep-linking with Flutter Web? - flutter

Flutter Web: Is there a way to make the URLs for an app appear similar to the navigation route name so that we can do deep linking? For e.g. if I run an app now on chrome, the URL I get is "http://localhost:51322/#/". So if I am on the home screen, how can I have it as "http://localhost:51322/#/home"?
I tried the solution at https://medium.com/flutter-community/more-than-a-flutter-web-app-is-a-full-flutter-website-c6bb210b1f16, but it doesn't seem to work anymore.

The section of the url after the # is the "route name" from "named routes" which are explained pretty well here: https://flutter.dev/docs/cookbook/navigation/named-routes
Specifically to change from "/" to "/home" as your default route, you want to change the "initialRoute" parameter to MaterialApp to "/home" and make sure your routes map has an entry for "/home" instead of "/"
There are a few ways to tell MaterialApp what the "home" or "root" Widget is, you will want to be careful that you don't give it conflicting instructions. The specifics are in the class documentation: https://api.flutter.dev/flutter/material/MaterialApp-class.html

Related

How to print the current route path in flutter using auto_router?

I have been using auto_route in my flutter app for navigation. I'm wondering if there's any way to print the current route path (example: /home/profile...). It'll be of great help while debugging and managing the routes.
Is there any way to do it?
It's a very simple implementation, just use this line
print(context.router.currentPath);
By below line you can get curent route:
ModalRoute.of(context).settings.name

How to use deep link in flutter web using navigator 2.0 on my webserver?

I can refresh(reload) and deep link when I launch debug in IDE(vscode)
However when I published to own webserver(I made web resource from this command 'flutter web build'), My webserver is intercept my url and return 404.. :(
It can enter from main page only
Webserver is runing on golang and Flutter web using navigator 2.0
How can I solve this?
I can't find reference of flutter navigator 2.0 in web.
Please save my life
The problem because removed hash(#) in url
I was follow this
How to remove hashtag (#) from url in web flutter
but this is cause that problem
When I back to original url(include hash), problem solved.
Please have a look at this code sample that uses new MaterialApp.router() constructor to handle url path.
In the parseRouteInformation of the RouteInformationParser you get the raw url and it's up to you how are you going to interpret the data. For instance, in the above sample the route is converted to object TheAppPath and later handled by RoutePageManager and RouterDelegate.

Flutter Navigator default route route in Fluro package

I am using Flutter with Fluro package and I want to set a default route for the app.
The need is to have a place to decide which path the user needs to navigate to, and from there to navigate the app by whatever settings decided upon.
Currently, I defined the routes in the app and do have a "404" (not found) route as described in the docs of the package, but I prefer to have another way which is more correct to solve it.
For example, the app has the routes:
"homepage"
"splash_screen"
"search"
"not_found"
"init"
I want the route init to be the default one.
Thank you,
Nisim
After digging some more I found the Fluro package has internal class RouteTree which handles all routes. when adding a new route it will check if it defaults by comparing it to Navigator.defaultRouteName (value "/").
Note: it allow you to add only one default route and will throw an exception if you do it more then one.
Adding the default route with handler solved the issue and now the default route is the one deciding about the next route and displays something in the meantime.

Using iron-router with angular-meteor makes controllers being loaded twice

I have a Meteor application using angular-meteor. I need now to load different angular modules depending on url. I added iron-router to my application to do so and I continue to handle routes for each module using ngRoute and anchor nav but it behaves strangely if url contains params. I made a small test case which is available here:
https://github.com/clouchtibat/iron-router-ng-route
If you click on 'truc' link and then on 'test', next routes changes will make controller be instantiated two times. It works if urls have no params.
I also tested with ui-router (in the with-ui-router branch) and the problem is the same but in addition view is duplicated.
Is this a bug in one of the two routers or is there something wrong with my implementation?
Take a look at this conversations in the angular-meteor Github issues:
https://github.com/Urigo/angular-meteor/issues/154
https://github.com/Urigo/angular-meteor/issues/493
I think it can help you with some directions.
I am also having some hard time with mixin angular-meteor and iron:router.

how do i redirect a specific path to another path in nginx?

I need to redirect a specific path:
mydomain.com/old-path/
to a new path, permanently:
mydomain.com/new-path/
i am using elgg software (elgg.org) and presently when someone navigates to the /old-path/ folder they view a page (rather than a folder listing) - thus no specific page name is used.
i tried the various methods of redirecting that can be found via google for nginx and so far none have had any effect. they mostly are either for a specific page or a directory, yet what i am doing, is, i suppose, technically neither a specific page or a directory..
anyone know how to achieve this?
thanks
You can use nginx HttpRewriteModule to do this.
rewrite ^/old-directory/(.*)$ /new-directory/$1 last;