1

I am currently developing a single page application on Salesforce. I have used ngRoute to navigate the user through the website. I've created a visualforce page and immidietly ran into a problem - on localhost when I had:

<a href="/home">Home</a>

it worked as expected, but when I deployed it to the salesforce clicking on the link actually went to /home and threw an 404. The workaround I found was to make a helper function:

$scope.goto = function (path)
{
  $location.path(path);
};

and rework links to:

<a href="#" ng-click="goto('/home')">Home</a>

And it loads content into ngView just fine, BUT it does not change the URL address. On localhost, even with this workaround, it changes to localhost/xyz/home, but on salesforce it does not. My base tags are set to /xyz/on localhost and to / on salesforce.

Also is there a way to implement ".htaccess" on Salesforce? On localhost I've made a rule to redirect all requests below xyz/ to index.html (so that when user is on /contant page they can refresh the link and not get a 404 error; or can copy the link and their friends can use it) but how can you achive this result on salesforce?

Every answer will be much appreciated. Thank you for the response in advance.

Best,

Mariusz

4

Remember that you are developing a "single page application" meaning that the URL in the browser needs to stay:

/apex/NameOfYourSinglePage

Angular routing can be then appended to the single page URL as a fragment identifier e.g.:

/apex/NameOfYourSinglePage#/Home".

So make your URLs relative:

<a href="#/home">Home</a>

This Salesforce Angular sample application is a good reference to start from.

You can build an Angular app on Salesforce where the URLs are correct and bookmarkable and refreshable.

(Force.com Sites do support URL Rewriting but normal Salesforce pages do not.)

| improve this answer | |
  • Thank you for your response. I wonder if it is possible to use $locationProvider to get rid of the hash and make pretty urls. For example have /apex/NameOfYourSinglePage/Home instead of /apex/NameOfYourSinglePage#/Home – mpiatek Jan 4 '16 at 10:07
  • @mpiatek See e.g. AngularJS routing without the hash '#'. But if I read that correctly your app would then not work in IE9 (caniuse.com/#feat=history). – Keith C Jan 4 '16 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.