{"id":156,"date":"2026-05-20T15:45:21","date_gmt":"2026-05-20T15:45:21","guid":{"rendered":"https:\/\/gigz.pk\/php\/?post_type=lesson&#038;p=156"},"modified":"2026-05-21T14:42:32","modified_gmt":"2026-05-21T14:42:32","slug":"routing-basics","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/php\/?lesson=routing-basics","title":{"rendered":"Routing Basics"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction to Routing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Routing is the process of directing users from one page or section of a website to another. It helps web applications display the correct content when users visit different URLs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Routing is an important part of modern web development because it improves navigation, user experience, and website structure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Objectives<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By the end of this training, you will be able to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand the concept of routing<\/li>\n\n\n\n<li>Learn how URLs work in web applications<\/li>\n\n\n\n<li>Create basic routes<\/li>\n\n\n\n<li>Handle dynamic routes<\/li>\n\n\n\n<li>Understand route parameters<\/li>\n\n\n\n<li>Use navigation links effectively<\/li>\n\n\n\n<li>Improve website structure using routing<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What is Routing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Routing connects a URL to a specific page, component, or function in a web application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example URLs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/home<br>\/about<br>\/contact<br>\/services<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each URL loads different content for the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Importance of Routing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Routing helps developers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Organize website pages<\/li>\n\n\n\n<li>Improve user navigation<\/li>\n\n\n\n<li>Create dynamic applications<\/li>\n\n\n\n<li>Manage multiple pages efficiently<\/li>\n\n\n\n<li>Enhance user experience<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Routing<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Static Routing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Static routes point to fixed pages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/about<br>\/contact<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Dynamic Routing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Dynamic routes use variables or parameters in URLs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/product\/101<br>\/user\/15<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The numbers represent unique IDs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Routing Example<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">HTML Navigation<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;a href=\"\/home\"&gt;Home&lt;\/a&gt;<br>&lt;a href=\"\/about\"&gt;About&lt;\/a&gt;<br>&lt;a href=\"\/contact\"&gt;Contact&lt;\/a&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Routing in PHP<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php<br><br>$page = $_GET&#91;'page'];<br><br>if($page == \"home\"){<br>    echo \"Home Page\";<br>}<br>elseif($page == \"about\"){<br>    echo \"About Page\";<br>}<br>else{<br>    echo \"Page Not Found\";<br>}<br><br>?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Routing in JavaScript<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>const routes = {<br>  \"\/\": \"Home Page\",<br>  \"\/about\": \"About Page\",<br>  \"\/contact\": \"Contact Page\"<br>};<br><br>console.log(routes&#91;\"\/about\"]);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Route Parameters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Route parameters allow dynamic data in URLs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/product\/25<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, 25 is the product ID.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of Route Parameters<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Load dynamic content<\/li>\n\n\n\n<li>Create user profiles<\/li>\n\n\n\n<li>Display product details<\/li>\n\n\n\n<li>Build scalable applications<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Navigation and Links<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Navigation links help users move between pages easily.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;nav&gt;<br>  &lt;a href=\"\/home\"&gt;Home&lt;\/a&gt;<br>  &lt;a href=\"\/services\"&gt;Services&lt;\/a&gt;<br>  &lt;a href=\"\/blog\"&gt;Blog&lt;\/a&gt;<br>&lt;\/nav&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Routing Best Practices<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Use Simple URLs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Good URL example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/web-development-course<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Avoid Complex URLs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Bad URL example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/page?id=123&amp;category=5&amp;type=data<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Keep Navigation Clear<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Users should easily understand website structure.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Use Meaningful Route Names<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Choose names related to the page content.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Routing Errors<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Page Not Found Error<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Occurs when a route does not exist.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Broken Links<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Happen when navigation links are incorrect.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Duplicate Routes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Multiple routes pointing to the same page can cause confusion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Applications of Routing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Routing is used in:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>E-commerce websites<\/li>\n\n\n\n<li>Learning management systems<\/li>\n\n\n\n<li>Blogs and news portals<\/li>\n\n\n\n<li>Social media platforms<\/li>\n\n\n\n<li>Business websites<\/li>\n\n\n\n<li>Web applications<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages of Routing<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Better website organization<\/li>\n\n\n\n<li>Improved navigation<\/li>\n\n\n\n<li>Faster page management<\/li>\n\n\n\n<li>Enhanced user experience<\/li>\n\n\n\n<li>Easier maintenance<\/li>\n\n\n\n<li>SEO friendly URLs<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Final Presentation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In your final presentation, explain:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What routing is<\/li>\n\n\n\n<li>Why routing is important<\/li>\n\n\n\n<li>Types of routing<\/li>\n\n\n\n<li>Static and dynamic routes<\/li>\n\n\n\n<li>Route parameters<\/li>\n\n\n\n<li>Navigation links<\/li>\n\n\n\n<li>Real-world applications of routing<\/li>\n<\/ul>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/php\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Professional PHP > MVC Concept > Routing Basics<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779291923873\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":53,"template":"","class_list":["post-156","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Routing Basics - Learn PHP with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn routing basics for web development including URLs, navigation, static routes, dynamic routes, and routing examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/php\/?lesson=routing-basics\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Routing Basics - Learn PHP with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn routing basics for web development including URLs, navigation, static routes, dynamic routes, and routing examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/php\/?lesson=routing-basics\" \/>\n<meta property=\"og:site_name\" content=\"Learn PHP with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-21T14:42:32+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=routing-basics\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=routing-basics\",\"name\":\"Routing Basics - Learn PHP with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\"},\"datePublished\":\"2026-05-20T15:45:21+00:00\",\"dateModified\":\"2026-05-21T14:42:32+00:00\",\"description\":\"Learn routing basics for web development including URLs, navigation, static routes, dynamic routes, and routing examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=routing-basics#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=routing-basics\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=routing-basics#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/php\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Professional PHP > MVC Concept > Routing Basics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/\",\"name\":\"Learn PHP with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Routing Basics - Learn PHP with GiGz.PK","description":"Learn routing basics for web development including URLs, navigation, static routes, dynamic routes, and routing examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/php\/?lesson=routing-basics","og_locale":"en_US","og_type":"article","og_title":"Routing Basics - Learn PHP with GiGz.PK","og_description":"Learn routing basics for web development including URLs, navigation, static routes, dynamic routes, and routing examples.","og_url":"https:\/\/gigz.pk\/php\/?lesson=routing-basics","og_site_name":"Learn PHP with GiGz.PK","article_modified_time":"2026-05-21T14:42:32+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/php\/?lesson=routing-basics","url":"https:\/\/gigz.pk\/php\/?lesson=routing-basics","name":"Routing Basics - Learn PHP with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/php\/#website"},"datePublished":"2026-05-20T15:45:21+00:00","dateModified":"2026-05-21T14:42:32+00:00","description":"Learn routing basics for web development including URLs, navigation, static routes, dynamic routes, and routing examples.","breadcrumb":{"@id":"https:\/\/gigz.pk\/php\/?lesson=routing-basics#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/php\/?lesson=routing-basics"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/php\/?lesson=routing-basics#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/php"},{"@type":"ListItem","position":2,"name":"Professional PHP > MVC Concept > Routing Basics"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/php\/#website","url":"https:\/\/gigz.pk\/php\/","name":"Learn PHP with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}