Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In a fairly complicated web application, there are almost hundreds of redirectin

ID: 649979 • Letter: I

Question

In a fairly complicated web application, there are almost hundreds of redirecting to another page, or linking to another page, etc. Imagine that you have a page called /services/users/register-new-user and in many places you want to redirect users to this page, or you want to provide links to this page. However, if for any reason in future, you change this address to something like /users/register, you should update all links, otherwise they won't resolve. I'm finding myself always encountering this problem, since wherever I want to redirect or link to /services/users/register-new-user I hard-code the entire relative address.

How can I improve this pattern?

Explanation / Answer

The most obvious thing that springs to mind is to hold the address in a variable and always use that when building the URL you need.

Then if you change the URL you just need to update the variable.

Other alternatives are to use a pattern like MVC routes to build up your addresses. Then you just need to update the logic that defines your routes.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote