I am pretty new to react, and I've encountered an error that I am not quite sure how to search for. The error I am facing is that if I don't place the paths I want in my index.tsx then it fails to render both my /create and /manage pages.
my Activities.tsx code in question is set as follows:
<Fragment key={uuid()}>
<Container>
<Route exact path='/' component={HomePage}/>
<Route exact path='/activities' component={ActivityDashboard}/>
<Route path='/activities/:id' component={ActivityDetails}/>
{/* This bit of code seems to literally do nothing, odd as the one above is fully functional */}
<Route path={['/createActivity', '/manage/:id']} component={ActivityForm}/>
</Container>
<NavBar />
</Fragment>
The dashboard merely loads my list of activities and returns the following:
<Fragment>
<Search
value={search}
onSearchChange={handleSearch}
/>
<Segment clearing>
<Item.Group divided>
{myActivities.map(activity => (
<Item key={activity.id}>
<Item.Content>
<Item.Header as='a'>{activity.title}</Item.Header>
<Item.Meta>{new Date(activity.date).toLocaleString()}</Item.Meta>
<Item.Description>
<div>{activity.description}</div>
<div>{activity.city}, {activity.venue}</div>
</Item.Description>
<Item.Extra>
<Button as={Link} to={`/activities/${activity.id}`} floated="right" color="blue" content="View" />
<Button name={activity.id} onClick={(e) => deleteActivity(e, activity.id)} loading={target === activity.id && submitting} floated="right" negative content="Delete"/>
<Label basic content={activity.category}></Label>
</Item.Extra>
</Item.Content>
</Item>
))}
</Item.Group>
</Segment>
</Fragment>
The index.tsx is set as:
const routing = (
<BrowserRouter>
<Menu fixed='top' inverted>
<Menu.Item header as={NavLink} exact to ="/">
<Image src="/assets/logo.png" alt="logo" size="mini">
</Image>
</Menu.Item>
<Menu.Item name="Activities" as={NavLink} to="/activities">
Activities
</Menu.Item>
</Menu>
<Route exact path="/" component={HomePage}/>
<Route path="/activities" component={Activities}/>
<Route path={["/createActivity", "/manage/:id"]} component={ActivityForm}/>
</BrowserRouter>
);
ReactDOM.render(routing, document.getElementById('root'));
If I remove the last route path in my index.tsx then it won't navigate to where it needs too. This is odd to me as I would suspect it to work the same way as my code for viewing the activity. Is there something basic that I am missing?
<Route path={["/createActivity", "/manage/:id"]} component={ActivityForm}/>you can no longer load either of those routes? confused about the question, also you dont want to set the key of a component (the fragment) to something that changes on render, which I presumeuuid()does as it generates a new one when called?/activitiesor keep them in the index.tsx file