I needed to get JRoute working in backend so that from admin I can create an event with my event component and have an email sent that contains the SEF url. After researching, I found some tips that involve setting the app instance to site, call JRoute, then set app back to admin. However, while I am getting the SEF url, something isn't quite right during the redirect after the event creation.

Here is how I do this, which is basically a copy from an older post I found:

```
$live_site = substr(JURI::root(), 0, -1);
    if(JPATH_BASE == JPATH_ADMINISTRATOR) {
        // In the back end we need to set the application to the site app instead in order for JRoute to work
        JFactory::$application = JApplication::getInstance('site');
    }

    // Create the URL
    $url = $live_site . JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . $id . '&Itemid=' . $Itemid);

    // Check if we are in the backend again
    if(JPATH_BASE == JPATH_ADMINISTRATOR) {
         // In backend we need to remove administrator from URL as it is added even though we've set the application to the site app
        $eventLink= str_replace($live_site .'/administrator', $live_site, $url);
        // Set the appilcation back to the administartor app
        JFactory::$application = JApplication::getInstance('administrator');
    }               

```

The above seems to work, but the problem is during the redirect, after the event has been created and the email sent. Normally, the event view page in admin has this type of url:

administrator/index.php?option=com\_icagenda&layout=edit&id=23

But because of the JApplication::getInstance business, the redirect url is messed up and I get a 500 error. The messed up url has this form

administrator/index.php/component/icagenda/?view=event&layout=edit&id=23

I think maybe the solution I pasted was from Joomla 1.5 and so maybe I need to do something differently in 3? 

Any ideas?

Thanks!