Do you use the URL as a navigation aid (aka redirect if URL is incorrect)?

Updated by Brady Stroud [SSW] 1 year ago. See history

123
<introEmbed body={<> <introYoutube url="http://www.youtube.com/embed/1j3m4A9Tlhc" description="Figure: Watch the URL working as a navigation aid" /> MVC gives us great URLs, but you need to help users navigate via the URL. If the user changes a URL, and the route parameters no longer match, you should correct them with a redirect. </>} />
public ActionResult Edit(string employeename, int id)
{
var model = _repository.GetEmployee(id);
// check for a parameter match and redirect if incorrect
if (string.IsNullOrEmpty(employeename) || employeename != model.EmployeeName)
{
return RedirectToAction(
"Edit", new { employeename = model.EmployeeName, id });
}
return View(model);
}

✅ Figure: Figure: Good example - The comment says it all Wordpress and Stack Overflow have URL formats that do this very well

✅ Figure: Figure: Good example - If the "settimeout-or-setinterval" part of th eURL changes, the page will redirect to the correct location

Acknowledgements

Adam Cogan
Damian Brady
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star