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

1 Answer 1

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.)

2
  • 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 Commented Jan 4, 2016 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). Commented Jan 4, 2016 at 10:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.