Step-by-Step
Angular Routing
Learn to create client-side
and Single Page Apps with
Routing and Navigation
by
NISHU GOEL
FIRST EDITION 2019
Copyright BPB Publications, India
ISBN: 978-93-88511-667
All Rights Reserved. No part of this publication may be reproduced or distributed in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication.
LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY
The information contained in this book is true to correct and the best of authors & publishers knowledge. The author has made every effort to ensure the accuracy of these publications, but cannot be held responsible for any loss or damage arising from any information in this book.
All trademarks referred to in the book are acknowledged as properties of their respective owners.
Distributors:
BPB PUBLICATIONS
20, Ansari Road, Darya Ganj
New Delhi-110002
Ph: 23254990/23254991
MICRO MEDIA
Shop No. 5, Mahendra Chambers,
150 DN Rd. Next to Capital Cinema,
V.T. (C.S.T.) Station, MUMBAI-400 001
Ph: 22078296/22078297
DECCAN AGENCIES
4-3-329, Bank Street,
Hyderabad-500195
Ph: 24756967/24756400
BPB BOOK CENTRE
376 Old Lajpat Rai Market,
Delhi-110006
Ph: 23861747
Published by Manish Jain for BPB Publications, 20, Ansari Road, Darya Ganj, New Delhi-110002 and Printed by Repro India Pvt Ltd, Mumbai
About the Author
Nishu Goel is a software developer currently working with IBM in Bengaluru, India. She has completed her Bachelor studies in computer science as in 2018. She works on Angular and keeps learning on the go. She loves to write blog posts and talk around the basic concepts of Angular at conferences. She is also the author of Angular for Beginners course on Udemy. With her work to apply technology towards sustainable development goals (SDGs) by the United Nations living in the villages of Jharkhand, India for three months, she has been awarded by the Prime Minister of the UK.
Some of her hobbies are: Working for community development with a focus on selective SDGs, Speaking at conferences, exploring places.
With this book, she aims to share her learning and understanding of the concepts of Angular Routing with everyone.
You can tweet her at @DcoustaWilson and read her blog posts at https://nishugoel.wordpress.com/
This book is dedicated to
my Papa and Mumma for
supporting what I wish to
do at every step of my life.
Foreword
Routing is one of the most important concepts for Angular developers. Whether you are just getting started in web development, or are an Angular expert, the mapping between the URL bar and the state of your application is a critical piece of functionality. Routing bridges the gaps between the individually addressable page model of the past and the rich client-side single page applications of today.
The Angular router is very powerful and this comes with some complexity. In the early days of Angular, it took the Angular team a few tries to get all of the complexity right. Nishus guide to the router covers everything that an Angular developer will need to know to take care of the most common use cases, but she also covers more advanced strategies that will take developers skill sets to the next level.
By acting as a guide to each of the learning steps that Angular developers should take in their journey with the router, she accelerates the learning process and hits important markers along the road, such as the nuances of handling asynchronicity with the router.
With this book, Nishu cements her place as a rising star in the Angular community.
Stephen Fluin, Developer Relations Lead, Angular
Preface
Building web applications has been done using HTML, JavaScript in the past a lot. When it comes to building large applications, libraries like Dojo, knockout etc. were used at a large scale. In 2009, the web developer community was taken by a storm when AngularJS was introduced. Misko Hevery and Adam Abronsbuilt it as a side project at Google and since then, this framework is not stopping to amaze people and help them build applications much faster and efficiently.
With the constant upgrades to this framework, it is growing more and more user-friendly and is now called Angular after the first version which was called AngularJS. From Angular 2 to the current version of Angular, the widely used name is just Angular irrespective of the version number.
At the time of writing this book, the version of Angular used is 7.3.7 and is very soon to be upgraded to Angular 8.
Some of the amazing features of Angular framework make it a widely-used framework for building single-page web applications. And one of the things that attracted me the most towards Angular framework was the so-simplified routing and navigation techniques in it and how it is so compatible with the Angular CLI (command-line interface).
And this was one of the driving factors for me to invest my time into writing this book about Angular Routing, having gathered some knowledge about how Routing works in Angular. I thought it would be a good idea to put together whatever I have learnt about routing in one place. The book has been put together trying to simplify all the concepts required to understand Angular Routing and at the same time, making sure that the reader grabs the most out of it and is able to code along his reading through the book.
The structure of this book is kept simple starting from the introduction of some of the basic concepts of Angular to get started, followed by the introduction to Angular Routing, basic set-up, concepts like guarding the routes, using parameters to route to different views, using lazy loading to improve the performance of the application etcet era.
I have tried my best to keep the language very simple to understand and used no heavy terms, in the hope of making this book an easy read for the audience and also a good read for the beginners in Angular.
The major motivation for me to write this book came from the person who has lived Angular for years and is the one who got me started in learning Angular right after my under-graduate studies. Mr. Dhananjay Kumar a.k.a DJ is the organiser of the Angular conference of India, ng-India and is a Developer Evangelist at Infragistics. He is the author of the book Angular Essentials. He has always been an inspiration whether it is his knowledge, hard-work, or the passion to teach people and help them grow.
Another one of the driving factors for me was my interest to write a book on a technical topic and after having learned some concepts of Angular with my major focus on Angular routing and having a clarity about Routing concepts, I decided to go for it.
The major learning sources for me in my journey of getting my basic concepts clear were DJ of course, the Pluralsight courses by Deborah Kurata, Software Developer, Pluralsight Author, and the official documentation of Angular, angular.io.
This book has a GitHub repository associated with it and the link to the repository is shared inside, because as we all have heard, the best way to learn something is by doing it.
Next page