Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

🧪 React: Standardseite einstellen mit Redirect

26.02.2021 (๐Ÿ‘407)


 

Mit Redirect kann man Seiten umleiten auf eine neue Adresse.

Dadurch kann man auch die Standard Startseite einer Webseite einstellen.

 

Code in der React App-Start-Datei App.js

App.js

<Route

 exact

 path="/"

 render={() => {

  return (

   <Redirect to="/๐Ÿ“œ" />

  )

 }}

 />

 

 

 

 

 

React Code App.js

import React, { Component } from 'react';

import { Route } from 'react-router';

import { Layout } from './components/Layout';

import { Articles } from './components/Articles';

import { Article } from './components/Article';

import { Edit } from './components/Edit';

import { Home } from './components/Home';

import ApiAuthorizationRoutes from './components/api-authorization/ApiAuthorizationRoutes';

import { ApplicationPaths } from './components/api-authorization/ApiAuthorizationConstants';

import { Redirect } from 'react-router'

import './custom.css'

export default class App extends Component {

    static displayName = App.name;

    render() {

        return (

            <Layout>               

                    <Route

                        exact

                        path="/"

                        render={() => {

                            return (

                                <Redirect to="/๐Ÿ“œ" />

                            )

                        }}

                    />

                <Route exact path='/' component={Articles} />

                <Route exact path='/๐Ÿ“œ' component={Articles} />

                <Route exact path='/๐Ÿ‘/:id' component={Article} />

                <Route exact path='/โœ/:id' component={Edit} />

                <Route exact path='/home' component={Home} />

                <Route path={ApplicationPaths.ApiAuthorizationPrefix} component={ApiAuthorizationRoutes} />

            </Layout>

        );

    }

}