Skip to content Skip to sidebar Skip to footer

How To Configure Controllers For Stateprovider With Typescript

Let's assume I have following simplified controller: module App { 'use strict'; export class StoreDetailController { constructor() { alert('Detail-Cont

Solution 1:

In this case, the most suspected, and mostly the culprit, would be inproper HTML setting.

Simply a browser needs to know, what is the basehref for all relative navigation. And that could be confusing for it (for the browser) if we navigate directly to https://domain/app/Store/Partial?name=Layout. To solve it we just need to set the element <base>

<base href="/" />

Check this Q & A about html5mode, with working example/plunker

Interestingly there is also other way for Angular's $htmlProvider, and it is it configuration:

$locationProvider.html5Mode({
   enable: true,
   requireBase: false.
});

Check the doc:

$locationProvider

small cite about configuration:

  • enabled – {boolean} – (default: false) If true, will rely on history.pushState to change urls where supported. Will fall back to hash-prefixed paths in browsers that do not support pushState.
  • requireBase - {boolean} - (default: true) When html5Mode is enabled, specifies whether or not a tag is required to be present. If enabled and requireBase are true, and a base tag is not present, an error will be thrown when $location is injected. See the $location guide for more information
  • rewriteLinks - {boolean} - (default: true) When html5Mode is enabled, enables/disables url rewriting for relative links.

Post a Comment for "How To Configure Controllers For Stateprovider With Typescript"