Deep Linking – Flex 3

Introduction

“Deep Linking” is a term used by web developers to describe support for URL-based navigation in applications that are not a traditional hierarchy of HTML pages.

At now what we are not able to do ?
By default, a Flex (and AJAX) application doesn’t work in traditional way. Our Flex application is accessible via one URL and you change what the user sees within the Flex application instead of switching to a new URL. In fact, switching to a new URL closes your application and, while it could open another Flex application at the new URL, you would lose the ability to make nice transitions between the visual states of your application and make it harder to share data between the application states, so typically you want to work within one URL, but then you don’t have the navigation features users expect such as back button, book marking, etc.
So, How Deep Linking helps me !
Deep Linking allows the URL to represent different “places” in a Flex application without closing the application as you change the URL. This is accomplished by using real or faked named anchors (depending on which browser you are using). Named anchors are parameters that follow the “#” in a URL that are normally used to navigate to different places within an HTML page.
You can put just about anything after the “#” and changing what is there doesn’t cause the page to re-load; therefore, the Flex application can remain running. The portion of the URL after the “#” is known as the fragment. If you change the fragment, the previous fragment gets stored in the browser history.
Nice, how it is Implementation !
In Flex 3.0, Deep Linking is implemented via the BrowserManager. The BrowserManager allows your application to set the fragment and receive notification when the fragment changes. There are new methods in URLUtils that help you convert an object full of property and value pairs to a fragment and vice-versa, but there is no support for creating or interpreting fragments directly from the components that make up the application. They’ve left this out for two reasons: One is that we want to eventually build a more automated way of providing deep linking in an application. The second reason is that there is a pretty good third party implementation called UrlKit. However, it is unlikely that anything they do will prevent you from using UrlKit in the future, so you should be able to use it in your applications without worry.
Adding Deep Linking To Your Application
Adding support for Deep Linking to your Flex 3.0 Application is relatively simple. The basic steps are:
1. turn off the HistoryManager (the HistoryManager also uses the BrowserManager and will interfere with your fragment processing)
2. initialize the BrowserManager with a default fragment and title
3. determine when you want to update the fragment and call BrowserManager.setFragment.
4. listen for events from the BrowserManager
5. when you receive an event, interpret the fragment and change your application accordingly

If you use Flex Builder, you must choose one of the HTML templates that support the BrowserManager. Go to the project’s Properties dialog, select “Flex Compiler” and ensure that the “Enable integration with browser navigation” is checked.
If you don’t use Flex Builder, you should modify one of the index.template.html files in a template folder that ends with “with-history”. You’ll need to copy the support files in the subfolders as well.

Leave a comment