Top

Delete a Page


Angular has given commands to create components. Those commands create few files and import those components.


But it doesn't provide any command yet to delete those components and remove those import line on its own. That we have to do on our own.


In this guide we will see what are the lines that you need to delete before deleting the entire folder of a component.

Removing a Component and routes :


When we create a new component ,imports it in the routes_name.routes.ts file, so before deleting the component folder we need to remove these import lines from that file.

Remove the import line at the top, and then remove the component_name from the declarations array.

Thats all the lines you need to remove before deleting the components folder, now you can delete the component_name folder.

If you want to remove a routes from the project, you just need to remove some lines from the routes.ts file.

Remove the below give lines from that file:

{
  path: 'new_routes_name_path',
  loadChildren: () => import('routes_name_path_folder/new_routes_name.routes')
},

Warning: Make sure that you remove the link for these pages that you have deleted from your sidebar as well. Follow our Sidebar Guide to know how to manipulate links in the sidebar.