Redirecting URLs that start with a #

Netlify _redirects file treats lines starting with # as comments.
Unfortunately, I have a bunch of old paths starting with # to redirect.

Can I escape the #? Or put the path in ‘’? What’s the recommended method?

Trying a / in front of the # did not work . . .

Hey @StarfallProjects

If there is a hash, you will need to do something client-side. See this post for more

In that case, is there a way to avoid Netlify tripping over code that includes the window object? We had client side redirects, but Netlify seemed to try to run the code on build - and fail because obviously no window. Not sure why it tried to run it in the first place . . .

Can you provide a sample of said code?

What happens when you build locally?

I should think it is not Netlify, but rather the SSG that is tripping over the code.

Our repo: GitHub - n8n-io/n8n-docs: n8n Documentation
The enhanceApp.js: https://github.com/n8n-io/n8n-docs/blob/main/docs/.vuepress/enhanceApp.js

It works fine when building locally and when building using GitHub actions and deploying to GitHub pages.

I’ve also been looking at our VuePress setup, but bit odd that it’s ok locally and not on Netlify.

I tried building the docs locally. Received the following error:

ReferenceError: window is not defined

Ok what the . . . I have done builds locally recently and they were fine. But yes, am now seeing this locally as well. We haven’t updated anything so . . .

Thanks for trying to help. I’m going to have to go poke one of our devs . . .

1 Like

I haven’t used VuePress much, but as it is a Vue app. Thus you likely want the code in the enhanceApp.js running as a beforeEnter, or beforeEach navigation guard in Vue Router.

Don’t poke too hard :slight_smile:

1 Like

Hey @StarfallProjects,

Here’s an actual context about the original issue:

That’s the reason why it won’t work even if you somehow add the redirects.

As far the window error is concerned:

Apart from what @coelmay suggested, another way to handle this window is not defined error is by wrapping it in an if statement:

if (window) {
  // use window here
}
1 Like