How can I get angular to page refresh without Hash links? On page refresh my angular app would error and not show the page it was just displaying, so I changed the html5Mode to false ( $locationProvider.html5Mode(false).hashPrefix(""); ) and now I can refresh the page. But I'm also getting the nasty prefix #/ in the link path.
How do I remove # in the url path while at the same time be able to refresh the page?
Explore this thread:
$location / switching between html5 and hashbang mode / link rewriting
You need to make sure all your links are absolute relative to index.html and you probably need a server rewrite.
Server rewrite will work on refresh, try to add middleware in your server.
Sample grunt configuration id below.
check https://github.com/parmod-arora/angular-url-rewrite for nginx and grunt serve rewrite.
middleware: function (connect) {<br>
var middlewares = [];<br>
middlewares.push(modRewrite([
'!/assets|\\.html|\\.js|\\.css|\\woff|\\ttf|\\swf$ /index.html'
]));
middlewares.push(connect.static('.tmp'));
middlewares.push(connect().use(
'/bower_components',
connect.static('./bower_components')
));
middlewares.push(connect.static(appConfig.app));
//middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
return middlewares;
}
Have you tried setting base in the head section of your html?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<base href="/">
</head>
Related
I have removed hash from my angular JS website using below code.
$locationProvider.html5Mode(true);
so my current url http://dev.dummpurl.loc/#/courses is replaced with http://dev.dummpurl.loc/courses.
my problem is browser gives me 404 if I ctrl+f5 http://dev.dummpurl.loc/courses.
is there any possible solution by which I can remove # from URL and at the same time runs if refreshed.
Use this code in the head
<base href="/">
And always return the index html file on request , if you are on to SPA(single page application)
I am using angularjs routing in my web app, and I have included the $locationProvider and the base tag in HTML head which is <base href="/webapp/"> in order to remove the hash symbol in the URL, it works fine when I redirect using anchor tags e.g. Home but gives a 404 error when I redirect using javascript e.g. window.location.href = '/webapp/home';. Tried everything but so far nothing, any help will be highly appreciated. Thank you in advance.
Try : Home
When you are using angular(JavaScript) routing; JavaScript routing start after # keyword in URL, other wise browser think this is the server side routing trigger; or page will get refresh.
USE : Home
$locationProvider will remove the # after redirecting to the the view.
I am creating a simple web proxy (which you can see on here) .
Everything is working OK except that resources on the target page, e.x <script src="/js/myScript.js"> redirect to MY WEBSITE/js/myScript.js which does not exist, because it was never meant to be ran on my proxy.
How would I point all links / resources to be fetched through my proxy (I made ascirpt that gets resources). All I need now is to make links / resources go there.
Please help.
There is always the tag. If you put it in the head and it will tell the browser what the base path for all relative URLs on the page is:
<head>
<base href="http://awebsite.com/">
</head>
See a more detailed explanation here
I am trying to use PhantomJS and angular-seo (https://github.com/steeve/angular-seo) to make my app crawlable.
As I am not using hashbangs, I've added the following meta tag to my app's header:
<meta name="fragment" content="!" />
In my main controller, I trigger $scope.htmlReady when the content is fully loaded:
$scope.$on('$viewContentLoaded', function() {
$scope.htmlReady();
});
I have loaded the seo module properly and while my server's app listens on port 4000 (I use an express server), I launch phantomJS on port 4040 with the following command:
phantomjs --disk-cache=no ./bin/angular-seo-server.js 4040 http://127.0.0.1:4000
If I check how things are working for the homepage with a simple curl 'http://127.0.0.1:4040/?_escaped_fragment_=' I get the correct HTML rendered properly.
But if I try a different route like http://127.0.0.1:4040/test?_escaped_fragment_= I only get <html><head></head><body></body></html> while http://127.0.0.1:4000/test works fine.
How can I make sure all my pages are indexed and not only my homepage?
I have built an iPhone webapp using PHP. The main (and only) page includes the apple-mobile-web-app-capable and apple-touch-fullscreen meta tags so that it can run fullscreen once added to the homescreen. However, it seems every time I launch the app from the homescreen, the cache version of the page is used instead of refreshing the page (and of course, I need the page to be updated on startup, and cannot use Ajax here - need to dynamically authenticate the user with SSO phpCAS). I did not use any manifest file and tried adding meta tags about cache without success. Does anybody know how to fix this?
Thanks
What meta tags have you tried?
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
should tell Safari not to cache, but I have not tried them.
You could use javascript to load your "real" startup page from the cached page using any of the standard techniques to make the URL unique, such as adding a random number.
That might even work for the main startup page, but I doubt it. Worth a try, though.
I suggest the cached page load a new page only if it is on the springboard:
UNTESTED suggestion:
window.onload = function () {
if (navigator.standalone) {
document.location.href = 'http://your.com/whatever.php?randomjunk=1234') }
}
so if the page is in the browser it can give instructions on saving to the home screen and if it is run from the home screen it will load the real page.
I know when you include a manifest file the main page is cached automatically, but I didn't think it happened when just using ...web-app-capable. Have you tried using a cache manifest file and listing your page under "Network:" to explicitly exclude it from this method of caching? If it isn't this it must be to do with the header and the meta information there.