3

I should create ExtJs4 app, which should have main menu, and each menu item should open a new page with different url, so if the user copies the url and pastes on other browser tab, the app should open that menu item.

I want to use ExtJs's recommended MVC architecture, but I don't know how I can use it with multiple pages/urls. All their examples are using single page.

One option is to reload the page each time when the user clicks on particular menu Item, so every url/menu item/page will be separate ExtJS app with it's MVC. But I think this approach has drawbacks, since the page will be reloaded every time and it's not good for performance. Also it's causes difficulties in reusing of components (common models, stores and views for different pages ).

So I would like to have one single app for all pages, but I don't know is there any solution to have different urls for different views (in my case: for different menu items).

Or is there another approach for such applications?

sha
  • 17,824
  • 5
  • 63
  • 98
Arshak
  • 716
  • 2
  • 7
  • 15
  • ExtJs approach is to have one application per page. What exactly are you trying to achieve? – sha May 24 '12 at 16:53
  • You probably would want to use [history](http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/history/history.html). – Molecular Man May 24 '12 at 19:24
  • It sounds like what you are looking for is the concept of Routes. These are available in Sencha Touch AFAIK, but not yet in ExtJS although from what I understand they are coming too. As @Molecular Man suggested you could right your own routes simply with a history controller. – dbrin Sep 13 '12 at 18:14

1 Answers1

2

You would probably want to use a Viewport, and make the Center Region a Container.

The Center Region Container would usually have a Card or Tab layout.

When the user navigates to a new view (Component), you add that view to the Container, and make it active.

The big mistake is to change the URL first. You don't want to do that.

You want to navigate, and then set the URL if the navigation was successful. You should probably not use ExtJS's History component, as it is incorrectly implemented. I would recommend using HTML5 pushState.

You should make sure your navigation system works without changing the URL bar too.

I would recommend reading up on Navigation in Microsoft Prism, WPF, and Silverlight, as there is more documentation there, and then apply that to ExtJS.

http://msdn.microsoft.com/en-us/library/gg430881(v=pandp.40).aspx

Here is an example Navigation process:

  • call app.requestNavigate('contacts/5'); you would add this yourself.

  • you parse this fragment to:

navigationContext = {  
  fragment: 'contacts/5',  
  xtype: 'contacts-form',  
  parameters:{  
    id: 5  
  }  
}

OPTIONAL: If using forms:

  • get active item from the navigation region (your center region). if exists, call confirmNavigationRequest(callback) . you will need to add this method or event.

  • if callback(true), proceed with the navigation. this allows the user to cancel a navigation, if say the form is "dirty"

END OPTIONAL

  • the easy way is to then create a new widget of navigationContext.xtype, add it to the navigation region, then call setActiveItem(widget). destroy the previous active item if it existed.

then call history.pushState(null, null, navigationContext.fragment)

then raise a 'navigatedto' event on the view, passing the context, and you can load the data from there.

More advanced scenarios include:

  • keep the previous component alive if you expect to return to it. add a keepAlive property and if true, don't destroy when add new components to container.

  • search the container and ask each component if it wants to handle the current navigation request (for example if a form loaded with contact-5 was already hidden in your navigation region, or if you want to re-use a form)

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • what you say is corrent and is exactly how i did my navigation mechanism. However, i didn´t get that about "You want to navigate, and then set the URL if the navigation was successful". That way is more complicated and we cannot use links to navidate. What I did is listen for changes in the url and search the controllers and ask them if they can handle the passed url. I would like to know which is the advantage that you find in your approach. thanx – lontivero May 25 '12 at 06:02
  • 1
    The problem is trying to rollback the URL if the user doesn't want to leave a dirty form. How did you handle that case? thx – Neil McGuigan May 25 '12 at 17:38
  • I got you, I´ve never considered that posibility. Thank you – lontivero May 26 '12 at 04:28
  • I created an example on similar lines using MVC and with browser history support: http://stackoverflow.com/questions/23572775/browser-history-with-extjs-mvc – 6ton May 14 '14 at 12:18