Matt Gimel
Matt Gimel

Reputation: 23

Render another root path with own routes

I am trying to figure render a complete seperate admin path with its own routes.

Is it possible to render say admin page that is with and existing project.

At the moment I have the following code it is working very well.

import React from 'react';
import ReactDOM from 'react-dom';
import App from './client/App.js';
import Admin from './admin/admin.js';

var pathname = window.location.pathname;

if (pathname.substring(0, 6) == '/admin') {
  ReactDOM.render(<Admin />, document.getElementById('root'));
} else {
  ReactDOM.render(<App />, document.getElementById('root'));
}

Upvotes: 0

Views: 217

Answers (1)

sshmaxime
sshmaxime

Reputation: 537

I'm struggling to understand what you want to do exactly. You already have everything you need, Admin and App are components and therefore small projects I would say. However, you shouldn't do it that way and instead use react-router it avoids you to check the window location pathname by yourself and will save you a lof of time and headache.

Upvotes: 1

Related Questions