Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I configure the base href for Angular 2 when using Electron?

Tags:

I need to either set <base> in the HTML or APP_BASE_HREF during the bootstrap for Angular 2 to not throw exceptions. If I set either of these then Electron, thinking in terms of the file system, throws exceptions in browser_adapter.ts when trying to match a route:

EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: 'C:'. Available routes: ['/dashboard', '/accounts'].

I tried using just the HashLocationStrategy mentioned in this blog post, but Angular still complains about the base href not being set.

like image 777
theblang Avatar asked May 17 '16 01:05

theblang


People also ask

What should be the base href in Angular?

The <base href="/"> tells the Angular router what is the static part of the URL. The router then only modifies the remaining part of the URL. Now that we've set the our base href tag, we can then move on to defining some routes without your route module file or your app.

What is the use of base href in angular 2?

The base href is the URL prefix that should be preserved when generating and recognizing URLs.

What is app base href?

The <base href> is used as the default base URL (see source code) when generating HTML5 style URLs for your web app. Additionally, it "specifies a base path for resolving relative URLs to assets such as images, scripts, and style sheets," namely your Angular distribution.


1 Answers

Since the href attribute can take a relative path and thanks to @DavidC and @ChristianRondeau in the comments on the question for verifying, it should work like this:

<base href="./"> 
like image 114
Abdulrahman Alsoghayer Avatar answered Sep 20 '22 06:09

Abdulrahman Alsoghayer