7

Given a simple page created in Servicenow with the following config:

Name: My Page
Url Suffix: my-page
Layout: foo

Inside of foo, I am loading in a single page application, with various routes such as /invoice/1, invoice/2, user/1, user/2 and so forth.

I am using react router for this routing, and although it loosely supports hash routing, it's clear that its considered for "old browsers". And as of 2.4.1 it seems that having _key= present is a requirement.

Anyway, ideally, I don't want to abuse hashbangs to describe a route, instead using the more typical url structure.

Current:

instance.servicenow/my-page#/invoice/1

Preferred:

instance.servicenow/my-page/invoice/1

This would require SN to know that anything deeper than my-page should redirect to my-page. I come from an apache world, in which case I would just write the following:

RewriteEngine On  
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

RewriteRule ^ /index.html [L]
Chris
  • 54,599
  • 30
  • 149
  • 186
  • The browser would redirect you and refresh the whole page without the #, which would not be what you want in a SPA. Your apache rule would also serve the whole page on every click, which is not intended in react – Gordon Mohrin Sep 02 '19 at 01:19
  • 1
    Hey @GordonMohrin thanks for the input. In both cases, React Router has a Link component, which under the hood manipulates the history state of the browser, so it wouldn't cause a refresh (and apache wouldn't get re-run). In saying that, the apache piece is just an example, however, everywhere where i use React/React Router this is possible by setting all pages to redirect to a single page (this is just the nature of SPA). Was just curious how to do it in SN – Chris Sep 02 '19 at 02:20

0 Answers0