Giter Site home page Giter Site logo

Comments (4)

chrisvfritz avatar chrisvfritz commented on August 19, 2024

No, unfortunately. As mentioned in the README:

Only works with routing strategies using the HTML5 history API.

from prerender-spa-plugin.

heinzdmx avatar heinzdmx commented on August 19, 2024

I am running into a similiar issue. I am using Vue.js on S3.
We want the following paths:

/
/somepath/sad
/about
/somepath/ads.html

The current code in index.js creates folders for a url and then a file named index.html. Unfortunately S3 forces redirects that causes /about to become /about/ in this case.

I have made a small change to index.js that enables us to have paths like this, I believe this is what @KenCorbettJr is trying to archive as well.

This code

        var folder = Path.join(self.staticDir, outputPath)
        mkdirp(folder, function (error) {
          if (error) {
            return reject('Folder could not be created: ' + folder + '\n' + error)
          }
          var file = Path.join(folder, 'index.html')
          FS.writeFile(
            file,
            prerenderedHTML,
            function (error) {
              if (error) {
                return reject('Could not write file: ' + file + '\n' + error)
              }
              resolve()
            }
          )
        })

Becomes

        var folder = Path.join(self.staticDir, outputPath.substr(0, outputPath.lastIndexOf("/")))
        var file = Path.join(folder, outputPath.substr(outputPath.lastIndexOf("/"), outputPath.length))

        if ('/' === outputPath.charAt(outputPath.length-1)) {
          file = Path.join(file, 'index.html')
        }

        function writeHTML() {
            FS.writeFile(
              file,
              prerenderedHTML,
              function (error) {
                if (error) {
                  return reject('Could not write file: ' + file + '\n' + error)
                }
                resolve()
              }
            )
        }

        if (file !== folder)
        {
          mkdirp(folder, function (error) {
            if (error) {
              return reject('Folder could not be created: ' + folder + '\n' + error)
            }

            writeHTML()
          })
        }
        else {
          writeHTML()
        }

If desired I can create a pull request with the code changes to enable this

from prerender-spa-plugin.

KenCorbettJr avatar KenCorbettJr commented on August 19, 2024

Thanks @heinzdmx for this snippet. At the very least I can add this to my own fork. You make a good point about the challenges in hosting this on S3. This library makes some assumptions about url rewrite rules that don't always apply. There may be instances where people have even changed their DirectoryIndex so that it serves a file with a different name other than index.html file when a request comes in to the folder. If that is the case this library would completely fail.

Even though it is an edge case, it would be nice if support was added to the library so that we wouldn't have to maintain our own fork, constantly merging in new code. It is a common enough use case that I think it makes sense. At the very least it gives this plugin the flexibility to work even when the hosting environment doesn't match the assumptions that were made. I think the current behavior is perfectly fine default, but it would be nice to have more options.

from prerender-spa-plugin.

heinzdmx avatar heinzdmx commented on August 19, 2024

@chrisvfritz
Would you mind taking a look at my comment, to see if that is something you would be willing to add support for?

from prerender-spa-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.