question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`basename` issues

See original GitHub issue

I can’t seem to get the basename property on navigation to work. I assume it serves the exact same purpose as react router’s basename.

Redirects and links seem to ignore it. Here is my main <App /> component:


function App() {
    const dispatch = useDispatch();
    const { profile } = useReduxState('user');
    const { fieldTypes } = useReduxState('app');

    useEffect(() => {
        dispatch(gapiInit());
    }, [dispatch]);

    return (
        <Router
            routes={routes}
            basename={BASEPATH}
            context={{ profile, fieldTypes }}
        >
            <MainLayout>
                <Suspense fallback={null}>
                    <View />
                </Suspense>
            </MainLayout>
            <Message />
            <ConfirmationDialogue />
        </Router>
    );
}

My main routes file


const routes = mount({
    '*': map((request, context) =>
        !context.profile || !context.fieldTypes
            ? redirect(
                  '/login?redirectTo=' +
                      encodeURIComponent(request.originalUrl),
                  { exact: false }
              )
            : map(() => {
                  store.dispatch(setConfirmRouteChange(false));
                  store.dispatch(setConfirmationDialogue(null));
                  return pageRoutes;
              })
    ),
    // Catches the root URL before login to avoid adding 'redirectTo' by default
    '/': map((request, context) =>
        !context.profile || !context.fieldTypes
            ? redirect('/login')
            : pageRoutes
    ),
    '/login': map(async (request, context) =>
        !context.profile || !context.fieldTypes
            ? route({
                  title: 'Login',
                  view: <LoginPage />
              })
            : redirect(
                  request.params.redirectTo
                ? decodeURIComponent(request.params.redirectTo)
                      : '/'
              )
    )
});

BASEPATH is set to /dist/. Navigating to localhost:8080/dist redirects me to localhost:8080/login.

Any help would be greatly appreciated 🙏

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

3reactions
jamesknelsoncommented, Jun 21, 2019

The basename option is a little different in Navi to react-router – it does affect routing, but doesn’t effect links/redirects. This allows basename to be used to integrate Navi with react-router and other routers, but also means that you’ll need to pass the full path for links/redirects.

One way to do this would be to add basename to the routing context and add it into redirects manually.

0reactions
OnkelTemcommented, Jun 25, 2020

Hmm, adding the basename to context is a solution for routing

Not in our case I’m afraid. We have dozens of components and, with a minor exception, they’re all written with the router-agnostic thought in mind. To give them Navi context woud mean editing all of them and making them more navi-dependent either by calling useCurrentRoute() from inside of the components or by wrapping all the components into a custom withRouter() hoc to get the context basename passed in props.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++11 - Issue with basename - Stack Overflow
So I am having an issue using basename for one of my programming assignments for school. I have tried getting a simplier version...
Read more >
basename problem - The UNIX and Linux Forums
Basename in subshell ... Hi All, I would like to improve my bash scripting skill and found a problem which I do not...
Read more >
Problems with basename in a loop - Unix Stack Exchange
This means your for loop is running with a single entry, and passing that file * to basename. Then, out=$(basename $arqin) is expanding...
Read more >
Problems with basename · Issue #5000 · remix-run/react-router
Hi guys, Congrats for the v4 release! I've problems using basename. The basename is prepended or removed depending on the use case.
Read more >
basename - The Open Group Publications Catalog
basename - return non-directory portion of a pathname. SYNOPSIS. basename string [suffix] ... Issue 6. IEEE PASC Interpretation 1003.2 #164 is applied.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found