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

Admin - handle non-existing routes #768

Open
doitadrian opened this issue Mar 23, 2020 · 5 comments · May be fixed by #1037
Open

Admin - handle non-existing routes #768

doitadrian opened this issue Mar 23, 2020 · 5 comments · May be fixed by #1037

Comments

@doitadrian
Copy link
Collaborator

@doitadrian doitadrian commented Mar 23, 2020

This is:

  • Bug

Detailed Description

If a user opens a non-existing route in the Admin app, a blank page is shown.

image

Possible solution

Let's create a simple "Not found" page.

An example that shows how a default route is registered can be found here. So basically, it's a route that doesn't have the path prop defined.

At this moment, I believe this route could be part of the @webiny/app-admin plugins. If so, it should be added here packages/app-admin/src/plugins/index.ts.

@amitsin6h
Copy link

@amitsin6h amitsin6h commented Apr 3, 2020

I would like to work on this

@Pavel910
Copy link
Collaborator

@Pavel910 Pavel910 commented Apr 3, 2020

@amitsin6h Awesome! Let us know if you need help with the setup. Please consult the CONTRIBUTING guide to help you get started.

We're also on https://gitter.im/Webiny/webiny-js if you need help.

@Anshuman71
Copy link
Contributor

@Anshuman71 Anshuman71 commented Jun 18, 2020

@doitadrian I followed your proposed solution steps and I added the plugin for no-matching-route but it is getting rendered on every route as I have not given a path prop. In <Swtich /> it takes the last route if no other route matches, I'm not sure how that works in webiny-js.
Can you please help me?

@Pavel910
Copy link
Collaborator

@Pavel910 Pavel910 commented Jun 18, 2020

Hi @Anshuman71, just tried this in our repo, this seems to work just fine:

// apps/admin/App.tsx

import adminTemplate from "@webiny/app-template-admin-full";
import "./App.scss";
import { Route } from "@webiny/react-router";
import React from "react";

export default adminTemplate({
    cognito: {
        region: process.env.REACT_APP_USER_POOL_REGION,
        userPoolId: process.env.REACT_APP_USER_POOL_ID,
        userPoolWebClientId: process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID
    },
    plugins: [
        {
            type: "route",
            name: "not-found-route",
            route: <Route render={() => <div>Route not found!</div>} />
        }
    ]
});

So, to make this work on a more global level, and not only in your app, I would add the following route:

<Route render={() => <Redirect to={opts.defaultRoute || "/"} />} />

At this here reference: packages/app-template-admin/src/index.tsx:64 so that it looks like this:

image

Let me know if you need more help!

@Anshuman71
Copy link
Contributor

@Anshuman71 Anshuman71 commented Jun 19, 2020

@Pavel910 thanks a lot.
When I add the plugin into apps/admin/App.tsx the Route Not Found message shows up on every route, as shown in the image below.

import adminTemplate from "@webiny/app-template-admin-full";
import "./App.scss";
import { Route } from "@webiny/react-router";
import React from "react";

export default adminTemplate({
    cognito: {
        region: process.env.REACT_APP_USER_POOL_REGION,
        userPoolId: process.env.REACT_APP_USER_POOL_ID,
        userPoolWebClientId: process.env.REACT_APP_USER_POOL_WEB_CLIENT_ID
    },
    plugins: [
        {
            type: "route",
            name: "not-found-route",
            route: <Route render={() => <div>Route not found!</div>} />
        }
    ]
});

Screenshot from 2020-06-19 06-49-34

However, If I use the app-template-renderer plugin from webiny-js/packages/app-template-admin/src/index.tsx and add

<Route component={() => <Redirect to={opts.defaultRoute || "/"} /> } />

to <BrowserRouter />, it takes re-directs all the unknows routes to default route.
Page Builder - Pages — Watch Video

That is the expected behavior and it solves the issue.
My only confusion now is that why I see the message on every route if I use the first approach, while it works for you.

@Anshuman71 Anshuman71 linked a pull request that will close this issue Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.