Skip to content

Commit

Permalink
ref/ make app reloading/working with and without usehash routing stra…
Browse files Browse the repository at this point in the history
…tegy
  • Loading branch information
Maxime GRIS committed Apr 20, 2020
1 parent 0994e6c commit 386ce67
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 27 deletions.
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as url from 'url';

let win: BrowserWindow = null;
const args = process.argv.slice(1),
serve = args.some(val => val === '--serve');
serve = args.some(val => val === '--serve');

function createWindow(): BrowserWindow {

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-electron",
"version": "7.0.3",
"version": "7.0.4",
"description": "Angular 9 with Electron (Typescript + SASS + Hot Reload)",
"homepage": "https://github.com/maximegris/angular-electron",
"author": {
Expand All @@ -22,7 +22,7 @@
"postinstall": "electron-builder install-app-deps",
"ng": "ng",
"start": "npm-run-all -p electron:serve ng:serve",
"build": "npm run electron:serve-tsc && ng build",
"build": "npm run electron:serve-tsc && ng build --base-href ./",
"build:dev": "npm run build -- -c dev",
"build:prod": "npm run build -- -c production",
"ng:serve": "ng serve",
Expand Down
11 changes: 9 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PageNotFoundComponent } from './shared/components';

import { HomeRoutingModule } from './home/home-routing.module';
import { DetailRoutingModule } from './detail/detail-routing.module';

const routes: Routes = [
{
path: '',
Expand All @@ -15,7 +18,11 @@ const routes: Routes = [
];

@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
imports: [
RouterModule.forRoot(routes),
HomeRoutingModule,
DetailRoutingModule
],
exports: [RouterModule]
})
export class AppRoutingModule {}
export class AppRoutingModule { }
3 changes: 3 additions & 0 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {

}
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

import { HomeModule } from './home/home.module';
import { DetailModule } from './detail/detail.module';

import { AppComponent } from './app.component';

Expand All @@ -32,6 +33,7 @@ export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
CoreModule,
SharedModule,
HomeModule,
DetailModule,
AppRoutingModule,
TranslateModule.forRoot({
loader: {
Expand Down
18 changes: 18 additions & 0 deletions src/app/detail/detail-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes, RouterModule } from '@angular/router';
import { DetailComponent } from './detail.component';

const routes: Routes = [
{
path: 'detail',
component: DetailComponent
}
];

@NgModule({
declarations: [],
imports: [CommonModule, RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class DetailRoutingModule {}
7 changes: 7 additions & 0 deletions src/app/detail/detail.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="container">
<h1 class="title">
{{ 'PAGES.DETAIL.TITLE' | translate }}
</h1>

<a routerLink="/">{{ 'PAGES.DETAIL.BACK_TO_HOME' | translate }}</a>
</div>
3 changes: 3 additions & 0 deletions src/app/detail/detail.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {

}
35 changes: 35 additions & 0 deletions src/app/detail/detail.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DetailComponent } from './detail.component';
import { TranslateModule } from '@ngx-translate/core';

import { RouterTestingModule } from '@angular/router/testing';

describe('DetailComponent', () => {
let component: DetailComponent;
let fixture: ComponentFixture<DetailComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DetailComponent],
imports: [TranslateModule.forRoot(), RouterTestingModule]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should render title in a h1 tag', async(() => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain(
'PAGES.DETAIL.TITLE'
);
}));
});
14 changes: 14 additions & 0 deletions src/app/detail/detail.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-detail',
templateUrl: './detail.component.html',
styleUrls: ['./detail.component.scss']
})
export class DetailComponent implements OnInit {

constructor() { }

ngOnInit(): void { }

}
13 changes: 13 additions & 0 deletions src/app/detail/detail.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { DetailRoutingModule } from './detail-routing.module';

import { DetailComponent } from './detail.component';
import { SharedModule } from '../shared/shared.module';

@NgModule({
declarations: [DetailComponent],
imports: [CommonModule, SharedModule, DetailRoutingModule]
})
export class DetailModule {}
2 changes: 2 additions & 0 deletions src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<h1 class="title">
{{ 'PAGES.HOME.TITLE' | translate }}
</h1>

<a routerLink="/detail">{{ 'PAGES.HOME.GO_TO_DETAIL' | translate }}</a>
</div>
19 changes: 3 additions & 16 deletions src/app/home/home.component.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
.container {
height: 100%;
display: flex;
align-items: center;
justify-content: center;

background: url(../../assets/background.jpg) no-repeat center fixed;
-webkit-background-size: cover; /* pour anciens Chrome et Safari */
background-size: cover; /* version standardisée */

.title {
color: white;
margin: 0;
padding: 50px 20px;
}
}
:host {

}
3 changes: 2 additions & 1 deletion src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { HomeComponent } from './home.component';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';

describe('HomeComponent', () => {
let component: HomeComponent;
Expand All @@ -10,7 +11,7 @@ describe('HomeComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [HomeComponent],
imports: [TranslateModule.forRoot()]
imports: [TranslateModule.forRoot(), RouterTestingModule]
}).compileComponents();
}));

Expand Down
3 changes: 2 additions & 1 deletion src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
selector: 'app-home',
Expand All @@ -7,7 +8,7 @@ import { Component, OnInit } from '@angular/core';
})
export class HomeComponent implements OnInit {

constructor() { }
constructor(private router: Router) { }

ngOnInit(): void { }

Expand Down
9 changes: 7 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"PAGES": {
"HOME": {
"TITLE": "App works !"
}
"TITLE": "App works !",
"GO_TO_DETAIL": "Go to Detail"
},
"DETAIL": {
"TITLE": "Detail page !",
"BACK_TO_HOME": "Back to Home"
}
}
}
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<meta charset="utf-8">
<title>AngularElectron</title>
<base href="">
<title>Angular Electron</title>
<base href="/">

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="assets/icons/favicon.ico">
Expand Down
42 changes: 42 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,46 @@ html, body {
padding: 0;

height: 100%;
font-family: Arial, Helvetica, sans-serif;
}

/* CAN (MUST) BE REMOVED ! Sample Global style */
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;

background: url(./assets/background.jpg) no-repeat center fixed;
-webkit-background-size: cover; /* pour anciens Chrome et Safari */
background-size: cover; /* version standardisée */

.title {
color: white;
margin: 0;
padding: 50px 20px;
}

a {
color: #fff !important;
text-transform: uppercase;
text-decoration: none;
background: #ed3330;
padding: 20px;
border-radius: 5px;
display: inline-block;
border: none;
transition: all 0.4s ease 0s;

&:hover {
background: #fff;
color: #ed3330 !important;
letter-spacing: 1px;
-webkit-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
-moz-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
box-shadow: 5px 40px -10px rgba(0,0,0,0.57);
transition: all 0.4s ease 0s;
}
}
}

0 comments on commit 386ce67

Please sign in to comment.