Redirect Functionality

Explore more about the redirect functionality that allows our application to change views based on the URL.

About the application

We need to add functionality that allows us to modify the web browser URL without reloading the application, and to re-render our application if the URL changes.

This is what the application looks like:

Note: To log in, use the username admin and password 123.

Copyright (c) 2020 John Sheehan

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Passing URL information to the main app

Modifications in the pyreact module

At line 30, look at the modifications in the render() function in the pyreact.py module located inside the bookapp/client/src/common/ folder that injects the current URL path and query parameters into the component props. With this information, our application will be able to perform view routing in the main App component using the URL in the web browser. Those minor changes made in this module are important to the redirect framework implementation.

Built-in JavaScript window methods as props

At lines 25 and 27, we have some built-in JavaScript window methods to get the URL path (location.pathname) and querystring parameters (location.search) which will be added as two additional props that ...