Giter Site home page Giter Site logo

ng1ng2router's Introduction

Migrating Angular 1 Applications to Angular 2.x Using NgUpgrade and Angular Router

Article

This is an example application for [Migrating Angular 1 Applications to Angular 2 in 5 Simple Steps] (https://vsavkin.com/migrating-angular-1-applications-to-angular-2-in-5-simple-steps-40621800a25b#.oj2pbb5de)

The application shows how to migrate an Angular 1 app to Angular 2 using the Angular 2 router. It uses WebPack 2.0 and AoT compilation.

How to Run

  • clone this repo

  • npm install

  • npm start

  • open localhost:8080

  • optionally npm run build to build bundle

Applicaiton

Modules

The application has three modules:

  • Main Menu
  • Messages
  • Settings

They illustrate the three stages of migrating modules from Angular 1 to Angular 2.

  • The Main Menu moduule is written in Angular 1. In other words, the migration of this module hasn't started yet.
  • The Messages module is written using Angular 1, but one of its components has been migrated to Angular 2.
  • The Settings module is written using Angular 1. In other words, the migration of this module has been completed.

Every module defintes components, services, and routes. In addition every module has an NgModule with a static methods where we can downgrade/upgrade, components and services.

Routes

These are the routes the application supports:

  • /
  • /messages/:folder
  • /messages/:folder/:id
  • /settings
  • /settings/pagesize

The first three routes are handled by the Angular 1 router, and the last two are handled by the Angular 2 router. We define a custom UrlHandlingStrategy to partition all URLs into these two sets.

Wiring it Up

See comments in ng2_app.ts and main.ts.

ng1ng2router's People

Contributors

vsavkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng1ng2router's Issues

UrlHandlingStrategy shouldProcessUrl(url:UrlTree) function should also provide another complete url parameter

After debugging the UrlHandlingStrategy I could see when a navigation to e.g. "/stocks" is made , the strategy.extract() is called twice , one for "/" and another for "/stocks". For a hybrid Ng1 & Ng2 ,where both have default "/" routes to different components , the arbitration becomes ambiguous as to which router should handle the default "/" route. Since the arbitration is on the Ng2 side it can make the distinction as to where the "/" extraction is from "/stocks" or "/phones" by know the full uri in a second parameter passed to the shouldProcessUrl(url :UrlTree, fullUrl:UrlTee)=> { url: "/", fullUrl: "/stocks").

I also noticed that when an anchor uses href <a href="#/stocks"> the router does not apply redirects , whereas <a routerLink="stocks" > gets processed by the router for redirection.
I have an example setup where the main app <phonecat> embeds components from a remote <stocks> app. and clicking on the href link works to bring up the stocks app in the <router-outlet> whereas the routerLink does not and gets redirected to the "/" of the phone cat app.

phone cat app : https://github.com/pdhar-tibco/phone-upgrade/tree/router-outlet
build and run : tsc && npm start

stocks app: https://github.com/pdhar-tibco/stocks
build & run : gulp build && npm start

Ng1Ng2Upgrade missing repository

Hi,

I just tried to clone and start this project.

The npm install gives some WARNings:

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN @angular/[email protected] requires a peer of [email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of [email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @ngtools/[email protected] requires a peer of @angular/compiler-cli@^2.1.0 but none was installed.
npm WARN @ngtools/[email protected] requires a peer of @angular/core@^2.0.0 but none was installed.
npm WARN [email protected] No repository field.

I think the last one is the most problematic one, when you try to npm start, you get the following error:

ERROR in ./src/main.ts
Module build failed: Error: C:/test-projekte/ng1ng2router-master (1)/ng1ng2router-master/src/main.ts (10,37): Cannot find module './ngfactory/src/ng2_app.ngfactory'.)
at _transpile (C:\test-projekte\ng1ng2router-master (1)\ng1ng2router-master\node_modules@ngtools\webpack\src\loader.js:101:19)
at C:\test-projekte\ng1ng2router-master (1)\ng1ng2router-master\node_modules@ngtools\webpack\src\loader.js:125:26
@ multi main

Best regards
Helmut

Routing issues in rendering AngularJS components from Angular routes.

Hi when I try to use <messages> component inside <settings> component, I was getting a blank page.. So downgraded the ng2Root comp in ng1 context. as suggested here
angular/angular#12965

So After that the routing strategy stopped working.. here is the repo which describes the problem.

https://github.com/a5hik/ng1ng2

PS: When I do after bootstrap platformRef.injector.get(Router).initialNavigation(); I can able to navigate \settings page directly from the browser, but not the other pages are working.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.