How come my route isn't matching with React Router 4? - react-router-v4

I have a routes file that works as expected:
<Route path="/app" render={({match}) => (
<Switch>
<Route exact path={`${match.url}/`} component={Home} />
<Route path={`${match.url}/error`} component={Error} />
</Switch>
</Route>
But when I try to hard code the routes, it does not work. For example:
<Route path="/app" render={({match}) => (
<Switch>
<Route exact path={`app/`} component={Home} />
<Route path={`app/error`} component={Error} />
</Switch>
</Route>
Of course hard coding is not what I really want, but in case I wanted to do something like this
<Route path="/app">
<Switch>
<Route exact path="app/" component={Home} />
<Route path="app/error" component={Error} />
</Switch>
</Route>
And create the app using the Children of the Route and not the render prop. What am I doing wrong, or how can I accomplish this?

React router V4 doesn't use nested routes.
<Route path="/app"> will match anything that begins with /app, which I don't think is what you want.
This should be enough to do what you want:
<Switch>
<Route exact path={`/app/error`} component={Error} />
<Route path={`/app`} component={Home} />
</Switch>

Related

How can I determine the route of the application through deep linking based on the link

This is my code
‍App.js‍ :
function App() {
const getInitialURL = async () => {
const url = await Linking.getInitialURL();
console.log('This is url',url)
if (url !== null) {
return url;
}
return undefined
}
const deepLinking = {
prefixes: ['https://www.example.com','https://*.example.com','http://www.example.com','app://'],
config: {
initialRouteName:'HOME',
screens: {
HOME: 'home',
LIVE: 'live/:uuid',
TAGList: 'tag/:enVal'
}
},
getInitialURL
}
return (
<NavigationContainer linking={deepLinking}>
<stack.Navigator
initialRouteName={'SPLASH'}
screenOptions={{headerShown: false}}>
<stack.Screen name = "SPLASH" component={Splash}/>
<stack.Screen name = 'HOME' component = {Home}/>
<stack.Screen name = "LIVE" component={LiveOne}/>
<stack.Screen name = "TAGList" component={TagList}/>
</stack.Navigator>
</NavigationContainer>
);
}
export default App;
android/app/AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="app" />
<data android:scheme="https" android:host="www.example.com" />
<data android:scheme="http" android:host="www.example.com" />
<data android:scheme="https" android:host="example.com" />
<data android:scheme="http" android:host="example.com" />
</intent-filter>
So, with this code, when I click on the link started by example.com, the app opens HOME screen, but I need for example, when the example.com is clicked, the HOME screen opens, and when the example.com/m/uuid is clicked, the app opens and change the screen to the LIVE screen and send the uuid to the same screen
For now, I can only open LIVE screen app with same params with this command :
npx uri-scheme open "app://LIVE/3a35ed925895A26" --android
I need when click on the example.com/m/3a35ed925895A26 app opened LIVE screen with 3a35ed925895A26 params
Well, I found the solution myself
1- I had to make changes in the code in order to be able to access the app both through app:// and through various link models (with http without http - with https without https - with www without www).
In AndroidManifest.xml file :
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
//for app://
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="app" />
</intent-filter>
//for links
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="www.example.com" />
<data android:scheme="http" android:host="www.example.com" />
<data android:scheme="https" android:host="example.com" />
<data android:scheme="http" android:host="example.com" />
</intent-filter>
2- And deep linking prefixes :
prefixes: [
'https://www.example.com',
'http://www.example.com',
'https://*.example.com',
'http://example.com',
'https://example.com',
'app://'
]
3- Now for example my link is something like this : www.example.com/m/876c875dDfV3, In order to be able to access the route /m through deep link, I need to define its route in screens as m/:uuid.
/m is route in my links, And :uuid is my params to this route, You can use your params or you're link structure.
config: {
initialRouteName:'home',
screens: {
HOME: 'home',
LIVE: 'm/:uuid',
TAGList: 'tag/:enVal'
}
}

How to stack the same component when editing after writing

<Stack.Screen name="Complain" component={Complain} />
<Stack.Screen name="ComplainList" component={ComplainList} />
<Stack.Screen name="ComplainUpdate" component={Complain} />
How do I stack it up? Complain === ComplainUpdate
<Stack.Screen name="Complain" component={Complain} />
<Stack.Screen name="ComplainList" component={ComplainList} />
<Stack.Screen name="ComplainUpdate" component={ComplainUpdate} />
I've copied the same components and stacked them up, but this doesn't seem like a good idea. Is there any good way?
<Stack.Screen name="Complain" component={Complain} />
<Stack.Screen name="ComplainList" component={ComplainList} />
<Stack.Screen name="ComplainUpdate" component={ComplainUpdate} />
<Stack.Screen name="ComplainAdd" component={ComplainAdd} />
just.. copy and paste.. i'm sorry

Something went wrong page after after pressing on DeleteButton

Everytime I click on a delete button in a List component, the page shows this error page.
The deletion works though.
The error page
export const MaterialList = props => (
<List {...props}>
<Datagrid rowClick="edit">
<NumberField source="REGEL_ID" />
<DateField source="STAND" />
<NumberField source="MaterialID" />
<NumberField source="DruckstufenID" />
<TextField source="Bezeichnung" />
<TextField source="Bezeichnung2" />
<TextField source="pA_Artikel" />
<TextField source="Menge" />
<NumberField source="DefaultHaken" />
<NumberField source="Verdichten" />
<TextField source="pA_Artikel_Original" />
<EditButton />
<DeleteButton />
</Datagrid>
</List>
);
Is there someone who atleast understands the error message?
We noticed this bug a few days ago and it has been fixed in v3.3.3.

react-router default page does not work

When a user clicks refresh on the server, or tries to enter a url path in the application that does not exist, I want them to be directed to the login page. I thought adding this default route would fix it:
<Route path='*' component={LoginPage}/>
While it works on the dev server, it does not work in production with Apache. What am I dong wrong?
Here is my entire routes page:
export default (
<Route path={VC.BASEPATH}>
<IndexRoute component={LoginPage}/>
<Route path={VC.BASEPATH} component={App}>
<Route path={VC.BASEPATH + "home"} component={HomePage}/>
<Route component={Builder}>
<Route path={VC.BASEPATH + "builder/admin"} component={AdminPage}/>
<Route path={VC.BASEPATH + "builder/survey_builder"} component={SurveyBuilderPage}/>
<Route path={VC.BASEPATH + "builder/survey_details"} component={SurveyDetailsPage}/>
</Route>
<Route component={Search}>
<Route path={VC.BASEPATH + "search/draft"} component={SurveyQueryContainerPage}/>
<Route path={VC.BASEPATH + "search/prod"} component={ProdSurveyPage}/>
</Route>
</Route>
<Route path={VC.BASEPATH + "preview"} component={PreviewPage}/>
<Route path='*' component={LoginPage}/>
</Route>
);

Extend a Custom Apache Knox Service to query multiple HBase tables

I'm currently working on extending the functionality of Apache Knox interacting with HBase on HDP 2.3.2. I've created a new gateway on Apache Knox called Decode, to query HBase. The Decode Gateway was built using the HBase gateway as a template. Topologies have been edited such that the following query:
curl -ku admin:admin-password -H "Accept: application/json" https://sandbox.hortonworks.com:8443/gateway/default/decode/hbase/MyHBaseTable/HBaseRowKey123*
Will return the data from Row 123 (In Base 64)
Is there way to change the Decode gateway's rewrite.xml and service.xml so that the query would not need to go through Hbase, e.g:
curl -ku admin:admin-password -H "Accept: application/json" https://sandbox.hortonworks.com:8443/gateway/default/decode/MyHBaseTable/HBaseRowKey123*
I understand this may sound strange to not use in inbuilt HBase gateway but the overall aim is to extend the Decode gateway such that It would be able to query multiple tables and/or multiple rows of data from HBase, rather than one row at a time.
Currently my Decode rewrite.xml is:
<rules>
<rule dir="IN" name="DECODE/decode/inbound" pattern="*://*:*/**/decode/{path=**}?{**}">
<rewrite template="{$serviceUrl[DECODE]}/{path=**}?{**}"/>
</rule>
<rule dir="IN" name="DECODE/decode/inbound" pattern="*://*:*/**/decode{**}">
<rewrite template="{$serviceUrl[DECODE]}/{path=**}?{**}"/>
</rule>
<filter name="WEBHBASE/webhbase/status/outbound">
<content type="*/json">
<apply path="$[LiveNodes][*][name]" rule="WEBHBASE/webhbase/address/outbound"/>
</content>
<content type="*/xml">
<apply path="/ClusterStatus/LiveNodes/Node/#name" rule="WEBHBASE/webhbase/address/outbound"/>
</content>
</filter>
</rules>
and the service.xml:
<service role="DECODE" name="decode" version="0.0.1">
<routes>
<route path="/decode/**"/>
<route path="/decode/?**">
<rewrite apply="WEBHBASE/webhbase/headers/outbound" to="response.headers"/>
</route>
<route path="/decode/**?**">
<rewrite apply="WEBHBASE/webhbase/headers/outbound" to="response.headers"/>
</route>
<route path="/decode/status/cluster?**">
<rewrite apply="WEBHBASE/webhbase/status/outbound" to="response.body"/>
</route>
<route path="/decode/*/regions?**">
<rewrite apply="WEBHBASE/webhbase/regions/outbound" to="response.body"/>
</route>
</routes> <dispatch classname="org.apache.hadoop.gateway.hbase.HBaseDispatch"/> </service>
Just like #lmccay I don't see anything necessarily wrong with what you have shown so I decided to try it for myself.
In the default topology file I copied the WEBHBASE service to a DECODE service as shown.
/usr/hdp/current/knox-server/conf/topologies/default.xml
<service>
<role>WEBHBASE</role>
<url>http://my-hbase-hostname:60080</url>
</service>
<service>
<role>DECODE</role>
<url>http://my-hbase-hostname:60080</url>
</service>
I then copied the hbase service.xml and rewrite.xml from
/usr/hdp/current/knox-server/data/services/hbase/0.98.0
to a new directory
/usr/hdp/current/knox-server/data/services/decode/0.0.1
and modified them to look like the versions shown below. I basically just replaced all occurrences of hbase with decode using the matching case.
/usr/hdp/current/knox-server/data/services/decode/0.0.1/service.xml
<service role="DECODE" name="decode" version="0.0.1">
<routes>
<route path="/decode/?**">
<rewrite apply="DECODE/decode/headers/outbound" to="response.headers"/>
</route>
<route path="/decode/**?**">
<rewrite apply="DECODE/decode/headers/outbound" to="response.headers"/>
</route>
<route path="/decode/status/cluster?**">
<rewrite apply="DECODE/decode/status/outbound" to="response.body"/>
</route>
<route path="/decode/*/regions?**">
<rewrite apply="DECODE/decode/regions/outbound" to="response.body"/>
</route>
</routes>
<dispatch classname="org.apache.hadoop.gateway.hbase.HBaseDispatch"/>
<testURLs>
<testURL>/decode/version</testURL>
<testURL>/decode/version/cluster</testURL>
<testURL>/decode/status/cluster</testURL>
<testURL>/decode</testURL>
</testURLs>
</service>
/usr/hdp/current/knox-server/data/services/decode/0.0.1/rewrite.xml
<rules>
<rule dir="IN" name="DECODE/decode/root/inbound" pattern="*://*:*/**/decode/?{**}">
<rewrite template="{$serviceUrl[DECODE]}/?{**}"/>
</rule>
<rule dir="IN" name="DECODE/decode/path/inbound" pattern="*://*:*/**/decode/{path=**}?{**}">
<rewrite template="{$serviceUrl[DECODE]}/{path=**}?{**}"/>
</rule>
<rule name="DECODE/decode/location/outbound">
<match pattern="*://*:*/{path=**}?{**}"/>
<rewrite template="{$frontend[url]}/decode/{path=**}?{**}"/>
</rule>
<rule name="DECODE/decode/address/outbound">
<match pattern="{host}:{port}"/>
<rewrite template="{$frontend[url]}/hbase-region?host={host}?port={port}"/>
<encrypt-query/>
</rule>
<filter name="DECODE/decode/headers/outbound">
<content type="application/x-http-headers">
<apply path="Location" rule="DECODE/decode/location/outbound"/>
</content>
</filter>
<filter name="DECODE/decode/status/outbound">
<content type="*/json">
<apply path="$[LiveNodes][*][name]" rule="DECODE/decode/address/outbound"/>
</content>
<content type="*/xml">
<apply path="/ClusterStatus/LiveNodes/Node/#name" rule="DECODE/decode/address/outbound"/>
</content>
</filter>
<filter name="DECODE/decode/regions/outbound">
<content type="*/json">
<apply path="$[Region][*][location]" rule="DECODE/decode/address/outbound"/>
</content>
<content type="*/xml">
<apply path="/TableInfo/Region/#location" rule="DECODE/decode/address/outbound"/>
</content>
</filter>
</rules>
I was then able to query a table with the curl command below. This does not contain hbase in the URL I believe answering your question.
curl -k -u guest:******** -H 'Accept: application/json' https://localhost:8443/gateway/default/decode/t1/*
{"Row":[{"key":"ZjE6djE=","Cell":[{"column":"ZjI6djI=","timestamp":1453139991995,"$":"ZjM6djM="}]}]}