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

use redirect with base prefix #156

Open
amoghh opened this issue Nov 12, 2021 · 3 comments
Open

use redirect with base prefix #156

amoghh opened this issue Nov 12, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@amoghh
Copy link

amoghh commented Nov 12, 2021

How do i get Single Spa Router work with base and redirects
the following is my router config

<template id="single-spa-layout">
    <single-spa-router base="/dev">
      <nav>
        <application name="navbar"></application>
      </nav>
      <main>
        <redirect from="/" to="/profile"></redirect>
        <route path="/profile">
          <application name="profile-spa"></application>
        </route>
      </main>
    </single-spa-router>
  </template>

My root config is hosted at xyz.com/dev/
i want path matching to happen with /dev as prefix hence i have used the base attribute but i also want redirects to happen from
/dev to /dev/profile and /dev/ to /dev/profile which isnt happening. please can anyone help

@amoghh
Copy link
Author

amoghh commented Nov 13, 2021

If i set up the routing in the following manner (using the prefix '/dev' in the redirects manually)

<template id="single-spa-layout">
    <single-spa-router base="/dev">
      <nav>
        <application name="navbar"></application>
      </nav>
      <main>
        <redirect from="/dev" to="/dev/profile"></redirect>
        <route path="/profile">
          <application name="profile-spa"></application>
        </route>
      </main>
    </single-spa-router>
  </template>

The path matching works fine and the redirect happens but only from /dev to /dev/profile The redirect does not work for /dev/ to /dev/profile

can anyone please help its a bit urgent

@joeldenning
Copy link
Member

I agree that redirects should take into account the base url, although it will need to be a breaking change of single-spa-layout since there are likely those relying on the existing behavior.

can anyone please help its a bit urgent

Trying to pressure myself and other maintainers to do work for you is not helpful, since you're using a free, open source project that you have not paid for. Please consider contributing a pull request implementing the feature rather than pressuring others to do work for you. I may be able to work on this later this week, but generally deprioritize issues where people pressure me or feel entitled to my time.

@amoghh
Copy link
Author

amoghh commented Nov 16, 2021

Hey @joeldenning sorry for coming of like that, i didn't mean to request a urgent change request or a bug fix, since there is less online support on this library i was just confused whether i was doing something wrong hence i wanted to know whether there was a work around possible or if there was something that i was missing.

I necessarily don't require the redirect to work with base prefix, i can work around that by setting the full redirects (including prefixes) no issues but as i mentioned in my last comment i did manage to get it partially working but its not redirecting if there is a trailing slash in the URL. Is it something that i am missing or doing wrong?

suppose my application URL is https:/google.com/dev
if i enter https:/google.com/dev it successfully redirects to https:/google.com/dev/profile and my spa is loaded fine
but if i enter https:/google.com/dev/ (with the slash) the redirect doesn't happen and my spa isn't loaded

The following is my template

<template id="single-spa-layout">
    <single-spa-router base="/dev">
      <nav>
        <application name="navbar"></application>
      </nav>
      <main>
        <redirect from="/dev" to="/dev/profile"></redirect>
        <route path="/profile">
          <application name="profile-spa"></application>
        </route>
      </main>
    </single-spa-router>
  </template>

@MilanKovacic MilanKovacic added the enhancement New feature or request label Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants