Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple redirection rules and HTTP404 handling #177

Open
wants to merge 3 commits into
base: dev_v2.3
Choose a base branch
from

Conversation

andyb1979
Copy link
Collaborator

I'm sure there's a better way to handle this ...

I wanted to implement some redirection rules for dead pages and HTTP404 handling. I haven't figured out how to set statuscode=404 which is needed

See ./AppRouter/redirectionRules which defines redirection rules

// Redirection URLs from - to
export const REDIRECTION_RULES = new Map<string, string>([
    ["/javascript-ohlc-chart", "javascript-candlestick-chart"],
]);

And App() which processes redirection using

    // Process redirection rules first
    const pathWithoutSlash = location.pathname.endsWith("/") ? location.pathname.slice(0, -1) : location.pathname;
    if (REDIRECTION_RULES.has(pathWithoutSlash)) {
        return <Navigate  to={REDIRECTION_RULES.get(pathWithoutSlash)}/>
    }

Http404 handling is done later on in App() where I have some dodgy logic which needs reviewing

basically

                <AppBarTop toggleDrawer={toggleDrawer} currentExample={currentExample}/>
                {isHttp404 ? <NotFound/> : pageContent}
                <AppFooter/>

which inserts in between the app top bar and footer OR the page content depending on if the URL is recognised or not

There's probably a better way to do this using React Router and <Route path="*"> however I wanted to hide the side menu bar when HTTP404 is detected

@codesandbox
Copy link

codesandbox bot commented Dec 23, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant