Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve static html file in angular app

I have an angular application such that the routing might look like this:

angular.module('app').config(function($routeProvider, $locationProvider) {
  $routeProvider

  .when('/', {
    templateUrl : 'views/home.html',
    controller: 'homeController'
  })
  .when('/foo', {
    templateUrl : 'views/foo.html',
    controller: 'fooController'
  })
  .otherwise({
    redirectTo : '/'
  });
  $locationProvider.html5Mode(true);
});

Now, this may be an overly simple question, but can I serve a static page that is never going to change and needs no added javascript from me without specifying it with a .when route? For example, say I want to serve Googles Webmaster tools verification like so:

/googlee23dc3443279f430.html

Do I really need to create a .when('/googlee23dc3443279f430.html') route?

EDIT: We also did a server rewrite to make it so that non '/' routes would still serve up the index.html file, as specified in this wiki (and to get html5mode(true) working on page refreshes):

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

Would be nice not to have to add rewriteconditions each time we want to add a static page

like image 955
user4272178 Avatar asked Nov 19 '14 23:11

user4272178


People also ask

Is angular good for static website?

The pre-render feature provided with Angular Universal allows you to quickly and easily transform an Angular application into a static website. The two main benefits are: better indexing for search engines and speed of your site (which is also a factor for search engines).

Is angular App static or dynamic?

Angular uses dynamic queries ( static: false ) by default, which simplifies queries. Developers can still explicitly set a query to static: true if necessary.

HOW include external HTML file in Angularjs?

Following is code from angular component to import external html. http. get('assets/included. html', { responseType: 'text' }).

Is an angular App static?

Both React and Angular 2/4 compile to static code. Most of the time, the development build is served using some sort of build tool like webpack, but at the end of the day, your front end application can be served from a static location, like an S3 bucket.


1 Answers

if the entire page should be replaced with static html, you can use a link with ng-href (to make it dynamic and data based and not hardcoded) - https://docs.angularjs.org/api/ng/directive/ngHref

like image 70
sagie Avatar answered Oct 23 '22 17:10

sagie